Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Page
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 booted
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Factories\HasFactory;
6use Illuminate\Database\Eloquent\Model;
7use Illuminate\Database\Eloquent\SoftDeletes;
8use Illuminate\Support\Str;
9
10class Page extends Model
11{
12    use HasFactory, SoftDeletes;
13
14    protected $fillable = [
15        'title', 'slug', 'content', 'meta_title', 'meta_description',
16        'status', 'position', 'created_by', 'updated_by',
17    ];
18
19    protected $casts = ['position' => 'integer'];
20
21    protected static function booted(): void
22    {
23        static::saving(function (Page $page) {
24            $page->slug = Str::slug($page->slug ?: $page->title);
25            if (auth()->check()) {
26                $page->updated_by = auth()->id();
27                $page->created_by ??= auth()->id();
28            }
29        });
30    }
31}