1

I follow the official documentation of laravel to create templates with blade.I'm trying to make my first template but doesn't work.

1)Stored in resources/views/default.blade.php --->

<html>
<head>
    @include('includes.head')
</head>
<body>
<div class="container">

    @include('includes.header')


    <div id="main" class="row">

            @yield('content')

    </div>

</div>
</body>
</html>

2)stored in resources/views/home.blade.php -->

@extends('layouts.default')
@section('content')
    I am the Home Page!
@endsection

3)Stored in boostrap/app.php -->

$app->get('/', function (){
    return view('home');
});

4) localhost:8000/ return this error -->

Whoops, looks like something went wrong. 2/2 ErrorException in FileViewFinder.php line 137: View [layouts.default] not found. (View: /home/vagrant/lumen/resources/views/home.blade.php)

in FileViewFinder.php line 137
at CompilerEngine->handleViewException(object(InvalidArgumentException), '1') in PhpEngine.php line 44
at PhpEngine->evaluatePath('/home/vagrant/lumen/storage/framework/views/96985f6d91158d600b1d1b64b5a3060d84415fda.php', array('__env' => object(Factory), 'app' => object(Application))) in CompilerEngine.php line 59
at CompilerEngine->get('/home/vagrant/lumen/resources/views/home.blade.php', array('__env' => object(Factory), 'app' => object(Application))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 199
at Response->__construct(object(View)) in RoutesRequests.php line 643
at Application->prepareResponse(object(View)) in RoutesRequests.php line 505
at Application->callActionOnArrayBasedRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 479
at Application->handleFoundRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 376
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in CorsMiddleware.php line 6
at CorsMiddleware->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CorsMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in RoutesRequests.php line 626
at Application->sendThroughPipeline(array('App\Http\Middleware\CorsMiddleware'), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28

1/2 InvalidArgumentException in FileViewFinder.php line 137: View [layouts.default] not found.

in FileViewFinder.php line 137
at FileViewFinder->findInPaths('layouts.default', array('/home/vagrant/lumen/resources/views')) in FileViewFinder.php line 79
at FileViewFinder->find('layouts.default') in Factory.php line 165
at Factory->make('layouts.default', array('obLevel' => '1', '__env' => object(Factory), 'app' => object(Application))) in 96985f6d91158d600b1d1b64b5a3060d84415fda.php line 4
at include('/home/vagrant/lumen/storage/framework/views/96985f6d91158d600b1d1b64b5a3060d84415fda.php') in PhpEngine.php line 42
at PhpEngine->evaluatePath('/home/vagrant/lumen/storage/framework/views/96985f6d91158d600b1d1b64b5a3060d84415fda.php', array('__env' => object(Factory), 'app' => object(Application))) in CompilerEngine.php line 59
at CompilerEngine->get('/home/vagrant/lumen/resources/views/home.blade.php', array('__env' => object(Factory), 'app' => object(Application))) in View.php line 149
at View->getContents() in View.php line 120
at View->renderContents() in View.php line 85
at View->render() in Response.php line 53
at Response->setContent(object(View)) in Response.php line 199
at Response->__construct(object(View)) in RoutesRequests.php line 643
at Application->prepareResponse(object(View)) in RoutesRequests.php line 505
at Application->callActionOnArrayBasedRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 479
at Application->handleFoundRoute(array(true, array(object(Closure)), array())) in RoutesRequests.php line 376
at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in CorsMiddleware.php line 6
at CorsMiddleware->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CorsMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in RoutesRequests.php line 626
at Application->sendThroughPipeline(array('App\Http\Middleware\CorsMiddleware'), object(Closure)) in RoutesRequests.php line 382
at Application->dispatch(null) in RoutesRequests.php line 327
at Application->run() in index.php line 28
Richard Ortiz
  • 29
  • 1
  • 1
  • 8

4 Answers4

6

The selected answer (https://stackoverflow.com/a/37625344/7506001) is incorrect.

@joeldg and @autista_z are both correct.

As of Lumen 5.4, Blade views are still available and usable, even though they're no longer documented.

Full example:

// In routes/web.php: 
$app->get('/', function () use ($app) {
  return $app->make('view')->make('home');
});

// In resources/views/default.blade.php:
<html>
  <head>...</head>
  <body>
    <div id="whatever">
      @yield('content')
    </div>
  </body>
</html>

// In resources/views/home.blade.php:
@extends('default')
@section('content')
  <p>I am the Home Page!</p>
@endsection
jpoesen
  • 69
  • 1
  • 2
  • 3
    It seems that beginning from Lumen 5.2 and on Lumen is meant to be stateless, which means, they've removed sessions, CSRF middleware, cookie middleware and made views less prominent. To people using Lumen 5.2 and up, if they need to get the documentation for views as it pertains to Lumen one should reference version 5.1 or try to extrapolate from the Laravel 5.2 and up docs. – racl101 Sep 01 '17 at 18:36
  • I think it's perfectly fine for a stateless API to render a template into a PDF and let the user download it. This means there is still a use for Blade in Lumen. Template are not just for web pages, you can use template for other things too – Christopher Thomas Nov 25 '21 at 15:32
3

Function @extends('name') find file "name.blade.php" or "name.php" in the directory "resources/views" If you use @extends('layouts.default'), it means, it find file file "default.blade.php" or "default.php" in directory "resources/views/layouts" (subfolder layouts in views)

But you have your "deafault.blade.php" in "resources/views" So it should by @extends('default')

Autista_z
  • 2,491
  • 15
  • 25
  • thanks a lot! :) thanks your explaination I understood what was wrong following laravel's guidelines. But in lumen doesn't work. – Richard Ortiz Jun 04 '16 at 08:45
3

The URL you mention is for Laravel not Lumen, Lumen is a lightweight Laravel, It's for API layer and backend job processing. I recommend Laravel instead.

Khesayed
  • 362
  • 3
  • 6
  • For little and light cms, you don't need to Install Laravel, with Lumen you can work with blade normaly. I'm currently working on Lumen 5.4 and blade runs like a charm. joeldg and autista_z have explained it better. – Fábio Nicolau de Lima Aug 04 '17 at 21:12
  • As mentioned [here](https://stackoverflow.com/a/29648574/842768), after Lumen 5.2, it's supposed to be only used for APIs. @Khesayed isn't wrong, use Laravel instead. – giovannipds Dec 01 '17 at 11:21
1

The selected answer is wrong, Lumen has blade installed by default. The return you are using won't work.

Your route needs to look like

$app->get('/', function () use ($app) {
  return $app->make('view')->make('index');
});
joeldg
  • 50
  • 3