Laravel blade debug view name on error
Solution 1
One way to tackle this problem is add a html
comments (not blade
ones as they will not be rendered in compiled view) in sections which get echoed.
@section('content)
<!-- FILE: app/views/main/index.blade.php -->
<Your Content Goes Here>
@stop
This html comment will get rendered in the compiled source of the view. Of course you will have to inspect the compiled view first to identify which view is the problematic one. But in my experience, this method work almost all the time.
Solution 2
I don't know how to de encrypt view names , but one method i do is to
{{dd('will you reach here ')}}
Trying to move this line from view to another to watch where php render reach .
I know it is not the right way nor the professional one , but it may help in some cases .
Solution 3
This is not exactly a problema, this is a compiled version of your view.
Laravel Blade System will compile all your views and subviews into a single file and, if you didn't change anything on them it will always try to use the compiled version, to speed up your system.
Sometimes is hard to know wich one of our views is related to that error. Using Sublime text, what I do is to hit CTRL-P (windows) and paste the number of the compiled view (1154ef6ad153694fd0dbc90f28999013) and it will bring it to me right away.
Of course, you won't do any changes on it. This is just way to find the view you have problems in, so you can then find the real file and fix it. If you know wich file is the problematic one, you don't have to do this, go directly to your file.
Solution 4
I found my answer after looking into source, when on the Whoops! page, just look for render in the sidebar, there will be the name of the view file...
Solution 5
I created a helper that checks to see if you are working locally or in development mode, It then outputs an HTML comment.
{{ printViewComment('mockup/reports@content') }}
<!-- Template: mockup/reports@content -->
I chose to name the comments like this path.file_name@yeild_name but I only wish this was an automated featured.
Hontoni
Updated on June 04, 2022Comments
-
Hontoni almost 2 years
when there is some error in view, L4 shows a nice trace, but cached filename: open: /var/www/webpage/app/storage/views/1154ef6ad153694fd0dbc90f28999013
howto during view-rendering-to-cache save view's path/name (in a comment or something)? Or better yet - to show it in the debug-error-page (its called whoops or something?)
Thanks ;)
-
Hontoni over 10 yearsThis is a little problema as i dont need the compiled view that you can bring with CTRL-P, you do fixes in the original view file
-
Antonio Carlos Ribeiro over 10 yearsYou won't do any changes on it. This is just way to find the view you have problems in, so you can then find the real file and fix it. If you know wich file is the problematic one, you don't have to do this, go directly to your file.
-
Hontoni over 10 yearsdid you understand that there is no simple way to find the original view file? I need to search for file that has similar text, with something like: find . -xdev -type f -print0 | xargs -0 grep -H "some_file_content"
-
Hontoni over 10 yearsWell, that is a quick workaround that is just fine for me, thanks =)
-
Hontoni almost 10 yearsthanks. there is more annoying problem, when there is an error in view eval, we get a blank page instead of pointer to the line with error...
-
Nico about 9 yearsThis should be the accepted answer. The line number corresponds to the compiled view, not the blade template.
-
okdewit over 7 yearsI would however wrap it in something like
@if(env('APP_DEBUG') == 1) <!-- comment --> @endif
. Even though the filename is not sensitive information, It's a good practice to not leak any debug info to end users. -
tharumax over 7 yearsI agree with @Fx32.
-
PaulH almost 5 years
<!-- {{ __FILE__ }} -->
shows the compiled filename, not the source