Commit e0368457 by hfpp2012 yinsigan

view composer

1 parent 957364cc
......@@ -17,4 +17,14 @@ class PagesController extends Controller
else
return 'No view available';
}
public function profile()
{
return view('pages.profile');
}
public function settings()
{
return view('pages.settings');
}
}
<?php
namespace App\Http\ViewComposers;
use Illuminate\View\View;
class ProfileComposer
{
public function compose(View $view)
{
$view->with('married', random_int(0, 1));
$view->with('test', 'say test');
}
}
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use View;
class ComposerServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
// View::composer('pages.profile', 'App\Http\ViewComposers\ProfileComposer');
View::composer(['pages.profile', 'pages.settings'], 'App\Http\ViewComposers\ProfileComposer');
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
......@@ -176,6 +176,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ComposerServiceProvider::class,
],
......
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Profile</div>
<div class="panel-body">
<p>{{ $married }}</p>
<p>{{ $test }}</p>
<p>{{ $age }}</p>
</div>
</div>
</div>
</div>
</div>
@endsection
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Profile</div>
<div class="panel-body">
<p>{{ $married }}</p>
<p>{{ $test }}</p>
<p>{{ $age }}</p>
</div>
</div>
</div>
</div>
</div>
@endsection
......@@ -13,6 +13,9 @@
Route::get('/', 'PagesController@index');
Route::get('/profile', 'PagesController@profile');
Route::get('/settings', 'PagesController@settings');
// Route::get('/users', function () {
// $users = [
// '0' => [
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!