I am new to Laravel and can’t seem to find the answer to a technical detail of the implementation. Essentially, when I put any given file inside the public
directory, for e.g. app.css
, and then navigate to localhost:8000/app.css
, the file gets served without me having to do anything.
This obviously leaves me wondering about how Laravel handles the request to localhost:8000/app.css
. To test things out, I tried adding a GET route inside web.php
as follows:
Route::get('/app.css', function() {
return 'Hello';
});
but when I navigate to localhost:8000/app.css
, it still returns the app.css
CSS file, not the ‘Hello’ text. This clearly means that Laravel first searches for a file inside the public
directory and if it can’t find one only then does it bring in the router.
My question is: Is this something that Laravel does or is it something that is done intrinsically by the built-in PHP server? In simpler words, is returning static files inside public
a concern of the server itself or of Laravel.
I tried inspecting the source code of Laravel but unfortunately I can’t trivially find any file where a check is made for a matching file in public
before serving it.