0

I am new to laravel and trying to make a panel for food delivery I have used Laravel default Registration and Login for User Category--Restaurant and then after user login , the user can Add restaurant details using route (/add_details) once the user has added restaurant details the user should not be able to go to that route (/add_details)

this will depend on a column in restaurant table (is_verified) how do i check that

I was thinking of using a Laravel middleware

but then i was stuck how laravel middleware $request variable works how can i get column value in middleware and verify it

or if any other simple but effective solution as i will be using it in sidebar.blade.php as well

so that i can hide the menu

3
  • 1
    When the user add the details, what the value supposed to be in a column is_verified ? and when the value will be changing of is_verified ? May 12, 2020 at 8:28
  • The user Table is Different The Restaurant table is difference when user Singup and login and adds his restaurant details then a row is added in restaurant table with is_verified = 0 Now admin verifies the is_verified to 1 May 13, 2020 at 9:21
  • If you have a restaurant_id in your user table then see edit of your answer. You don't need to first get user record then restaurant_id you can directly get it. And apply the middleware on that specific route. May 13, 2020 at 10:24

1 Answer 1

0

I made a middleware and added it to kernel.php and is using it in routes

Its working fine but i want to ask is this the right way i have done it

Route::get('/manage_cuisines', 'RestaurantCuisineController@create')->name('manage-cuisines')->middleware('restaurant_verified');

    <?php

    namespace App\Http\Middleware;

    use Closure;
    use Auth;
    use \App\User;
    use \App\Restaurant;

    class CheckRestaurantVerification
    {
        /**
         * Handle an incoming request.
         *
         * @param  \Illuminate\Http\Request  $request
         * @param  \Closure  $next
         * @return mixed
         */
        public function handle($request, Closure $next)
        {

            $restaurant = Restaurant::find(User::find(Auth::id())->restaurant_id);
            if($restaurant->is_verified == 0)
            {
                return redirect('home');
            }
            return $next($request);
        }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.