Skip to content

Basic Template

JP Barbosa edited this page Mar 20, 2016 · 4 revisions

Basic Template

Define template variable for all views
nano app/Providers/AppServiceProvider.php
    ...
    public function boot()
    {
        view()->composer('*', function ($view) {
            $layout = 'layouts.html';
            $view->with(compact('layout'));
        });
    }
    ...
Create template folder and template for HTML
mkdir resources/views/layouts
nano resources/views/layouts/html.blade.php
<!DOCTYPE html>
<html>
    <head>
        <title>Laravel Apz</title>
    </head>
    <body>
        @yield('content')
    </body>
</html>
Add the follow block to all views
@extends($layout)

@section('content')
    ...
@endsection
nano resources/views/articles/index.blade.php;  \
nano resources/views/articles/show.blade.php;   \
nano resources/views/articles/create.blade.php; \
nano resources/views/articles/edit.blade.php;   \
nano resources/views/authors/index.blade.php;   \
nano resources/views/authors/show.blade.php;    \
nano resources/views/authors/create.blade.php;  \
nano resources/views/authors/edit.blade.php;
Open some pages in the browser and check
open http://localhost:8000/articles
open http://localhost:8000/articles/create
Add basic template to Git
git add .
git commit -m "Add basic template"
Next step: Bootstrap