Commit 957364cc by hfpp2012 yinsigan

view 中共享数据

1 parent bc2186e5
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
namespace App\Providers; namespace App\Providers;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use View;
use Carbon\Carbon;
use Auth;
class AppServiceProvider extends ServiceProvider class AppServiceProvider extends ServiceProvider
{ {
...@@ -13,7 +16,16 @@ class AppServiceProvider extends ServiceProvider ...@@ -13,7 +16,16 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
// $age = Carbon::createFromDate(1993, 7 , 6)->age;
View::share('age', $age);
View::share('myname', 'Renato');
// View::share('auth', Auth::user());
View::composer('*', function($view) {
$view->with('auth', Auth::user());
});
} }
/** /**
......
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
<div class="panel-heading">Dashboard</div> <div class="panel-heading">Dashboard</div>
<div class="panel-body"> <div class="panel-body">
<h2>{{ Auth::user()->name }}</h2>
<h2>{{ $myname }}</h2>
<h2>{{ $age }}</h2>
<h2>{{ $auth->name }}</h2>
You are logged in! You are logged in!
</div> </div>
</div> </div>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!