Auth :: user()在ServiceProvider中返回null

时间:2018-07-04 12:13:01

标签: php laravel-5

我尝试在ServiceProvider中获取用户ID,但成功登录后Auth :: user()返回null,这是哪里出了问题?

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use View;
use App\Offer;
use Auth;
class MasterPageProfileServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        dd(Auth::user()); // => null
        $offersTrashed = Offer::onlyTrashed()->where('user_id',Auth::user()->id)->get();
        View::share('offersTrashed', $offersTrashed);
    }
}

0 个答案:

没有答案