Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

yahia1001's avatar

404 not found problem

so i do not have a complicated code all i have is use Illuminate\Support\Facades\Route; use App\Http\Controllers\CarsController; Route::resource('/views/cars', CarsController::class); in my web.php page

public function index() { return view('index'); // in my Controller page }

and i have index.blaed.php that basically says cars and that is it but i get 404 not found everytime

0 likes
30 replies
sr57's avatar

index.blaed.php -> index.blade.php

yahia1001's avatar

@sr57 oh sry i wrote it in my classes correctly i was just mistaken here

tykus's avatar

A bad view template filename will not result in a 404; what URL are you actually visiting @yahia1001?

1 like
yahia1001's avatar

@tykus i just run php artisan serve in cmd n go to this url //127.0.0.1:8000

Snapey's avatar

what's your whole web.php?

1 like
yahia1001's avatar

@Snapey <?php

use Illuminate\Support\Facades\Route; use App\Http\Controllers\CarsController;

/* |-------------------------------------------------------------------------- | Web Routes |-------------------------------------------------------------------------- | | Here is where you can register web routes for your application. These | routes are loaded by the RouteServiceProvider within a group which | contains the "web" middleware group. Now create something great! | */

Route::resource('/cars', CarsController::class);

that is basically it

tykus's avatar

Your route definition has changed; what URL are you visiting?

Route::resource('/views/cars', CarsController::class);
Route::resource('/cars', CarsController::class);
1 like
yahia1001's avatar

@tykus i just run php artisan serve in cmd n go to this url //127.0.0.1:8000 i am watching a course on youtube and he did the same n goes to this url it prints cars for him but give me an error only change i have as well is that i wrote .blade the wrong way here but i did it correctly in my classes

yahia1001's avatar

@tykus look that is all the code the code that he has and what he gets when he runs server //imgur.com/a/mh4MBnZ idk the diffrance between us i wrote exctally the same stuff as him like forget that /views i was just trying that and that is my code and what i get //imgur.com/a/9UQA3Jo

tykus's avatar

@yahia1001 I don't know the tutorial or what is different between your application and the tutorial based on the small amount of code you have shared here. What I can tell you is this route

// routes/web.php
Route::resource('cars', CarsController::class);

this Controller

// app/Http/Controllers/CarController.php
public function index()
{
	return view('cars.index');
}

and this view

//resources/views/cars/index.blade.php
<h1>Cars</h1>

Will not result in a 404

yahia1001's avatar

@tykus well thanks for help but my problem is that it always ends 404 not found error for me even after the changes u added i just tried exctally what u typed down

tykus's avatar

@yahia1001 are you able to get any Route to work? What is the result of php artisan route:list?

yahia1001's avatar

@tykus actually that just worked idk why but the //127.0.0.1:8000 does not i mean the video he just goes to //127.0.0.1:8000 and it works for him sry i am rly new to all of this

tykus's avatar

@yahia1001

@tykus i just run php artisan serve in cmd n go to this url //127.0.0.1:8000

you need to be running the built-in server in the project root directory, and visiting the URL it is serving on!

yahia1001's avatar

@tykus sry what does that mean like how do i know that server i mean//127.0.0.1:8000 that is the url i get after running php artisan serve in cmd

Sinnbeck's avatar

@yahia1001 I mean try running it. Stop the serve process, run the command and start serve again

tykus's avatar

@yahia1001 it will tell you:

$ php artisan serve
Starting Laravel development server: http://127.0.0.1:8000

That the to base url for your application - since your don't have a / root defined, you will get a 404 if you just visit http://127.0.0.1:8000 - you need to visit one of the defined route, e.g. http://127.0.0.1:8000/cars

yahia1001's avatar

@tykus so does he have a root defined and i do not that is why i get this error

tykus's avatar

@yahia1001 what did you mean by this

actually that just worked idk why

What worked?

yahia1001's avatar

@tykus going to 127.0.0.1:8000/cars instead of //127.0.0.1:8000/ cause going to //127.0.0.1:8000/ worked for him in the video but for me //127.0.0.1:8000/cars this worked for me but //127.0.0.1:8000/ give me 404 not found

okusax's avatar

@yahia1001 as i see you don't have any route defined for //127.0.0.1:8000/ so the only one working is //127.0.0.1:8000/cars, that's why you get a 404 when trying to reach /. You can saw that in the image you share https://imgur.com/a/AIGAARZ there isn't a definition for / (URI/Name/Action).

Maybe in the tutorial you are watching the teacher forgot to show he has / route defined and pointing to CarsController index.

I encourage you to watch the oficial laracast course https://laracasts.com/series/laravel-8-from-scratch it has all the basic information to start with Laravel (Jeffrey is an awesome teacher!)

krekas's avatar

You are starting everything wrong. Start learning from basics PHP. How to set up dev environment and only then slowly go for laravel

Please or to participate in this conversation.