-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPost.php
29 lines (24 loc) · 788 Bytes
/
Post.php
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
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
class Post extends Model
{
use HasFactory;
protected $fillable = ['title', 'cover_image', 'post_date', 'display_order', 'content', 'customer_id', 'auto_delete_at'];
public function customer()
{
return $this->belongsTo(Customer::class);
}
public static function boot()
{
parent::boot();
static::creating(function ($model) {
$model->customer_id = auth()->user()->customer->id;
});
static::addGlobalScope('customer', function (Builder $builder) {
$builder->where('customer_id', auth()->user()->customer->id);
});
}
}