Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
25.00% |
1 / 4 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Warehouse | |
25.00% |
1 / 4 |
|
25.00% |
1 / 4 |
10.75 | |
0.00% |
0 / 1 |
| scopeActive | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDefault | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| branch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| stocks | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 6 | use Illuminate\Database\Eloquent\Model; |
| 7 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 8 | |
| 9 | class Warehouse extends Model |
| 10 | { |
| 11 | use HasFactory, SoftDeletes; |
| 12 | |
| 13 | protected $fillable = [ |
| 14 | 'branch_id', |
| 15 | 'name', |
| 16 | 'address', |
| 17 | 'is_default', |
| 18 | 'status', |
| 19 | ]; |
| 20 | |
| 21 | protected $casts = [ |
| 22 | 'is_default' => 'boolean', |
| 23 | 'status' => 'boolean', |
| 24 | ]; |
| 25 | |
| 26 | public function scopeActive($query) |
| 27 | { |
| 28 | return $query->where('status', true); |
| 29 | } |
| 30 | |
| 31 | public static function getDefault() |
| 32 | { |
| 33 | return self::where('is_default', true)->first() ?? self::first(); |
| 34 | } |
| 35 | |
| 36 | public function branch() |
| 37 | { |
| 38 | return $this->belongsTo(Branch::class); |
| 39 | } |
| 40 | |
| 41 | public function stocks() |
| 42 | { |
| 43 | return $this->hasMany(WarehouseStock::class); |
| 44 | } |
| 45 | } |