Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

view()->composer(['errors.404'] not working #20953

Closed
gdinko opened this issue Sep 3, 2017 · 6 comments
Closed

view()->composer(['errors.404'] not working #20953

gdinko opened this issue Sep 3, 2017 · 6 comments

Comments

@gdinko
Copy link

gdinko commented Sep 3, 2017

  • 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

@gdinko
Copy link
Author

gdinko commented Sep 3, 2017

quick fix in App\Exceptions\Handler.php render method

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

this will render the correct view with correct data injected

@themsaid
Copy link
Member

themsaid commented Sep 4, 2017

use errors::404 instead of errors.404

@themsaid themsaid closed this as completed Sep 4, 2017
@carloshhr
Copy link

@themsaid useful comment ever!

@semihkeskindev
Copy link

use errors::404 instead of errors.404

you saved my life and time 😄 thank you so much

@udeyubi
Copy link

udeyubi commented Apr 8, 2022

use errors::404 instead of errors.404

thanks a lot. but...why.....

@josefernandoperezgarcia1998

Its works for me the coment of @themsaid,
public function boot() { view()->composer('errors::403', function($view){ $view->with('menus', Menu::menus()); }); view()->composer('layouts.pagina.pagina-plantilla', function($view){ $view->with('menus', Menu::menus()); }); view()->composer('welcome', function($view){ $view->with('menus', Menu::menus()); }); }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants