Display user's name on the navigation bar in layout view
MODIFY
app/Providers/AppServiceProvider.php
app/Providers/AppServiceProvider.php
@@ -4,6 +4,8 @@ namespace App\Providers;
use Illuminate\Support\ServiceProvider;
+use Auth;
+
class AppServiceProvider extends ServiceProvider
{
/**
@@ -13,7 +15,11 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
- //
+ view()->composer('*', function($view) {
+ $view->with([
+ 'userName' => Auth::user()->name
+ ]);
+ });
}
/**

MODIFY
resources/views/layout.blade.php
resources/views/layout.blade.php
</li>
<li class="dropdown">
<a href="#" class="dropdown__toggle">
- <i class="fa fa-user"></i> <i class="fa fa-caret-down"></i>
+ {{ $userName }} <i class="fa fa-caret-down"></i>
</a>
<ul class="dropdown__list">
<li>

Display user's name on the navigation bar in layout view