Answer the question
In order to leave comments, you need to log in
How to get rid of constant authentication check?
Hello! There is a task to implement a shopping cart. If the user is not authenticated, save the product in cookies, if authenticated then in the database. The problem is that I've implemented this with a permanent check in each add, delete, show... method of type if (Auth::check) i.e. each method starts with an if/else block.
I want to get rid of it, but I can't figure out how.
If through middleware, then it will turn out the same, but in intermediaries.
I'm not asking you to write code for me, just a hint or direction in which to move.
Answer the question
In order to leave comments, you need to log in
Need to read documentation: https://laravel.com/docs/8.x/container#binding-int... .
Well, do not forget about the transfer from cookies to the database when the user logs in
Create a group for routes and add checks on them through middleware
Route::middleware('auth')->group(function () {
// тут твои роуты для работы с корзиной
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question