jeudi 18 janvier 2018

Pass data into middleware - Laravel

I need to do a verify, if the user has made the request. Can I pass the requested variable into middleware?

route.php

    Route::group(['middleware' => 'isRichiedenteOrIncaricato'], function () {

    /*
    |--------------------------------------------------------------------------
    | Routes per gestire l'elaborazione delle richieste
    |--------------------------------------------------------------------------
    */
    Route::get('/elaborazione_richieste/{richiesta}', 'ElaborazioneRichiesteController@show');

    /*
    |--------------------------------------------------------------------------
    | Routes per gestire i commenti nella pagina elaborazione richieste
    |--------------------------------------------------------------------------
    */
    Route::post('/elaborazione_richieste/{richiesta}/comments','CommentsController@store');

});

isRichiedenteOrIncaricato.php

    public function handle($request, Closure $next)
{

    if (\Auth::user() && \Auth::user()->id == 1 || \Auth::user() && \Auth::user()->id == 2) {
        return $next($request);
    }else{
        $request->session()->flash('message.level', 'danger');
        $request->session()->flash('message.content', 'Non puoi visualizzare questa pagina, devi essere il richiedente o l\'incaricato!');
        return redirect('/home');
    }


}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mI8kWy
via IFTTT

Aucun commentaire:

Enregistrer un commentaire