First of all you have to find a template or create one on your own. I'm going to assume that you will use Bootstrap, so check out this link for a nice dashboard template. You can find many more (free or paid) if you Google it. So you finally found your template! What do you do next? I'll tell you my approach.
Open the template you downloaded and strip off all the contents without touching the positions. For example, in a template the main menu will probably be placed in a div like:
<div class="left-side">
<ul class="menu">
<li>...</li>
<li>...</li>
</ul>
</div>
Strip off the <ul>
and leave just the <div>
. There you will place your menu (You'll see later how).
After doing that in all the positions you're gonna have something like this:
<div>
<div class="left-side"></div>
<div class="main-content"></div>
</div>
Off course it's gonna be much more than that but you get the idea. This is your master layout. Create a folder in your views e.g. layouts
and save it there as master.blade.php
.
Now open it again and change it to:
<div>
<div class="left-side">@include('partials.menu')</div>
<div class="main-content">@yield('content')</div>
</div>
HOW MENU WORKS
Create a new file in your app directory (same level as routes.php) and name it
composers.php
Open
app/start/global.php
and at the end of the file placerequire app_path().'/composers.php';
This way the code in your
composers.php
file will be triggered in every call.Inside composers.php write the following code:
View::composer('layouts.master', function($view){ // Just a sample. Get all menu items from the database $menus = Menu::all() ; // This way $menus will always be available in your master.blade.php $view->with('menus', $menus); });
- Inside your views folder create a folder
partials
and inside that folder createmenu.blade.php
. Now openmenu.blade.php
and place the following code:
<ul>
@foreach($menus as $menu) <li>{{ $menu->title }}</li> @endforeach
</ul>
And your menu is ready!
Off course you will need to implement more logic, such us menu highlighting etc. but this will get you started.
HOW MAIN CONTENT WORKS
To have the your content appear in the main area, all your views must extend the master layout. Assuming that you have the following route:
Route::resource('posts', 'PostsController');
a call to e.g. h**p://www.example.com/posts will trigger the index
function in PostsController
class PostsController extends BaseController {
public function index()
{
$posts = Post::all();
return View::make('posts.index', compact('posts'));
}
}
which then will call the views/posts/index.blade.php
file
@extends('layouts.master')
@section('content')
@foreach($posts as $post)
<p>{{ $post->content}}</p>
@endforeach
@stop
pass to it the $menus variable and place it inside master layout.
I hope this will get you started and i also hope that there aren't any typos in my code!
And don't forget that in case of a ready template, will have to
Take care the assets management (.css, .js etc.) yourself
Have your code conform to the template stylesheets