I want to pass user id in the boot
function of the AppServiceProvider
class (as it written in the docs) but for some reason Auth::user()
object is empty.
myAppName/app/Providers/AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Auth;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191);
URL::forceScheme('https');
View::share('user_info', Auth::user());
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
And then in in some blade template:
<p></p>
As a result an error occurs:
Trying to get property 'id' of non-object
There is same error if want to pass Auth::user()->id
How to make it work?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NXc9my
via IFTTT
Aucun commentaire:
Enregistrer un commentaire