mardi 24 novembre 2015

access model data in middleware laravel 5.1

I have below route

Route::get('dashboard/edit/{id}', ['middleware' => 'edit', 'uses' => 'SubscribersController@editItem']);

and in my middleware

public function handle($request, Closure $next)
{
    if (auth()->user()->id != $item->subscriber_id )
        redirect ... 
    else
    return $next($request);
}

I'm using Subscriber model for users and Item model for holding inventory for each subscriber. and Item model has key subscriber_id

so in my middleware when accessing edit/{id} route I'm checking if auth()->user->id is same as Item->subscriber_id or not. but i don't know how to access items data in middleware



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire