i add this styntax to model :
public static function boot()
{
if(Auth::user()){
parent::boot();
static::saving(function ($model) {
$model->school_id = Auth::user()->school_id;
});
static::addGlobalScope('school_id', function (Builder $builder) {
$builder->where('school_id', Auth::user()->school_id);
});
}
}
goes well on the web, but not in API, error :
ErrorException: Undefined index: App\SmStudent in file /home/simsmar/public_html/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 241
.
Laravel Framework 5.8.37
when i delete "if(Auth::user())" and only "public static function boot()" it's still same error
Finnaly, i found the solution
just give
parent::boot();
in first line of statif function
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With