-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMenuSection.php
More file actions
52 lines (41 loc) · 1.14 KB
/
MenuSection.php
File metadata and controls
52 lines (41 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Cache;
use Spatie\EloquentSortable\Sortable;
use Spatie\EloquentSortable\SortableTrait;
class MenuSection extends Model implements Sortable
{
use SortableTrait;
protected $table = 'menu_sections';
protected $fillable = [
'location',
'column',
'title',
'title_key',
'sort_order',
'is_active',
];
protected $casts = [
'is_active' => 'bool',
'sort_order' => 'int',
];
public $sortable = [
'order_column_name' => 'sort_order',
'sort_when_creating' => true,
];
public function items(): HasMany
{
return $this->hasMany(MenuItem::class, 'menu_section_id');
}
protected static function booted(): void
{
static::saved(function (self $section) {
Cache::forget("menus.location.{$section->location}.v1");
});
static::deleted(function (self $section) {
Cache::forget("menus.location.{$section->location}.v1");
});
}
}