mardi 30 juillet 2019

Can we use same route for authenticated and non-authenticated users in laravel with same controller and same view?

// route which should be used by authenticated and unauthenticated user 
Route::get('user/send-parcel', 'User\SenderController@sendParcerl');

I have tried to add this route in web (outside this auth middleware). It works fine but in my controller i have to add user id if the user is logged in if the user is not logged in the user_id field should contain the value of NULL.

$user = Auth::user();
$parcel->user_id = isset($user) ? $user->id : NULL;

The main problem is if i put the route outside of Auth middleware than it will not get the Auth in my controller. so the code works fine with unauthenticated user but for authenticated user it also put NULL in user_id field



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire