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