Laravel 5.3: How to use Auth in Service Provider?

后端 未结 2 1541
轮回少年
轮回少年 2021-01-16 10:42

I am passing a value in shared view by taking value from table. I need to know user ID for the purpose but Auth::check() returns false. How do I do it? Below is

2条回答
  •  攒了一身酷
    2021-01-16 10:55

    You can use authentication directly in the controller file. Adding it in the middleware is a cleaner way of doing the authentication.

    For eg. In CategoriesController.php

    ...

    class CategoryController extends Controller {

    /**
     * CategoryController constructor.
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
    

    ...

    If you want to have a look at a complete example http://deepdivetuts.com/basic-create-edit-update-delete-functionality-laravel-5-3

提交回复
热议问题