Question:
How Laravel component recognized in one file but not in another?

Problem

I've solved this issue, But I'm EXTREMELY confused on what's going on here, and would like someone to explain it to me for future reference.

So I have a Laravel 10 Project and my first route is a welcome page


Route::get('/', function () { return view('welcome'); })->name('welcome');


I made a Blade Component that's just a static menu. I generated it, Copy/pasted the existing menu, made a slight edit, replaced block with <x-header-menu /> and it worked fine in the welcome view.



I then made a new php file from scratch, and in this view, The blade component was Not Recognized. When I loaded the page, It didn't work. WHAT? Code was copy/pasted from the welcome page. This view was inside a folder So


Views/welcome.blade.php

Vs

Views/info/info_page_1.blade.php


But I have other pages inside folders that use a different component that work fine. So I'm SUPER confused as to what's happening here. (Using PhpStorm IDE btw)



Now The Weirdest thing here though, Is when I deleted info_page_1.blade.php, copy/pasted the Welcome.blade.php to info_page_1.blade.php, Then copy/pasted old info_page_1.blade.php code, It worked.

So... WHAT HAPPENED HERE? Why could the Blade Component not be found with a new file but could be found with a copy/pasted already working file, In the same location with the same name?


Solutions

Found the answer immediately as I switched back...


Name your file


info_page_1.blade.php


instead of


info_page_1.php


Answered by: >Tyler Stone

Credit: >StackOverflow


Blog Links: 

>How do I customize controller actions in Laravel Jetstream?

>Run Laravel Project to Active Local Server

>How to show encrypted user id in URL in Laravel?

>How to fix Laravel LiveWire listener?


Nisha Patel

Nisha Patel

Submit
0 Answers