Framework: view()->composer(['errors.404'] not working

Created on 3 Sep 2017  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.5.1
  • PHP Version: 7.0.0
  • Database Driver & Version:

Description:

view()->composer(['errors.404'], function ($view) {
            $title = 'some text';
            $view->with('title', $title);
        });

The title var is not defined in views/errors/404.blade.php

Steps To Reproduce:

insert this code in AppServiceProvider->boot()

view()->composer(['errors.404'], function ($view) {
            $title = [config('dc.site_domain')];
            $title[] = trans('404.Ups something is missing.');
            $view->with('title', $title);
        });

try to print $title in /views/errors/404.blade.php

Most helpful comment

use errors::404 instead of errors.404

All 3 comments

quick fix in AppExceptionsHandler.php render method

if ($exception instanceof NotFoundHttpException) { return response()->view('errors.404', [], 404); }

this will render the correct view with correct data injected

use errors::404 instead of errors.404

@themsaid useful comment ever!

Was this page helpful?
0 / 5 - 0 ratings