Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
50.00% |
5 / 10 |
|
40.00% |
2 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Brand | |
50.00% |
5 / 10 |
|
40.00% |
2 / 5 |
10.50 | |
0.00% |
0 / 1 |
| auditExcept | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| user | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| boot | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getAll | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| findById | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use App\Support\Auditable; |
| 6 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 7 | use Illuminate\Database\Eloquent\Model; |
| 8 | |
| 9 | class Brand extends Model |
| 10 | { |
| 11 | use Auditable, HasFactory; |
| 12 | |
| 13 | protected function auditExcept(): array |
| 14 | { |
| 15 | return ['slug', 'thumbnail']; |
| 16 | } |
| 17 | |
| 18 | protected $table = 'brands'; |
| 19 | |
| 20 | protected $fillable = |
| 21 | [ |
| 22 | 'name', |
| 23 | 'slug', |
| 24 | 'thumbnail', |
| 25 | 'description', |
| 26 | 'created_by', |
| 27 | ]; |
| 28 | |
| 29 | /** |
| 30 | * Automatic created_by value assigned from logged in user |
| 31 | * */ |
| 32 | public function user() |
| 33 | { |
| 34 | return $this->belongsTo(User::class, 'created_by'); |
| 35 | } |
| 36 | |
| 37 | protected static function boot() |
| 38 | { |
| 39 | parent::boot(); |
| 40 | |
| 41 | static::creating(function ($query) { |
| 42 | $query->created_by = auth()->id(); |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Repository Methods |
| 48 | * */ |
| 49 | public static function getAll($is_pluck = false) |
| 50 | { |
| 51 | $query = self::query()->with('createdBy'); |
| 52 | $query->latest(); |
| 53 | |
| 54 | return $is_pluck ? $query->pluck('name', 'id') : $query->cursor(); |
| 55 | } |
| 56 | |
| 57 | public static function findById($id) |
| 58 | { |
| 59 | |
| 60 | return self::query()->findOrFail($id); |
| 61 | } |
| 62 | } |