Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 5 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Category | |
0.00% |
0 / 5 |
|
0.00% |
0 / 5 |
30 | |
0.00% |
0 / 1 |
| user | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jokes | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jokesByTitleDesc | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jokesByTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jokesByDateAddedDesc | |
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\Relations\BelongsTo; |
| 8 | use Illuminate\Database\Eloquent\Relations\BelongsToMany; |
| 9 | use Illuminate\Database\Eloquent\SoftDeletes; |
| 10 | |
| 11 | class Category extends Model |
| 12 | { |
| 13 | /** @use HasFactory<\Database\Factories\CategoryFactory> */ |
| 14 | use HasFactory; |
| 15 | use SoftDeletes; |
| 16 | |
| 17 | protected $table = 'categories'; |
| 18 | |
| 19 | protected $fillable = [ |
| 20 | 'name', |
| 21 | 'description', |
| 22 | 'user_id', |
| 23 | ]; |
| 24 | |
| 25 | public function user(): BelongsTo |
| 26 | { |
| 27 | return $this->belongsTo(User::class); |
| 28 | } |
| 29 | |
| 30 | public function jokes(): BelongsToMany |
| 31 | { |
| 32 | return $this->belongsToMany(Joke::class); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Returns the collection of related jokes in reverse |
| 37 | * order of their title. |
| 38 | */ |
| 39 | public function jokesByTitleDesc(): BelongsToMany |
| 40 | { |
| 41 | return $this->jokes()->orderBy('title', 'desc'); |
| 42 | } |
| 43 | |
| 44 | public function jokesByTitle(): BelongsToMany |
| 45 | { |
| 46 | return $this->jokes()->orderBy('title'); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Returns the collection of related jokes in reverse order |
| 51 | * of their creation date |
| 52 | */ |
| 53 | public function jokesByDateAddedDesc(): BelongsToMany |
| 54 | { |
| 55 | return $this->jokes()->orderBy('created_at', 'desc'); |
| 56 | } |
| 57 | } |