index.blaed.php -> index.blade.php
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
@sr57 oh sry i wrote it in my classes correctly i was just mistaken here
Follow the conventions here: https://laravel.com/docs/9.x/controllers#resource-controllers Look at proper naming.
Edit:
Good catch @sr57
A bad view template filename will not result in a 404; what URL are you actually visiting @yahia1001?
@tykus i just run php artisan serve in cmd n go to this url //127.0.0.1:8000
what's your whole web.php?
@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
Your route definition has changed; what URL are you visiting?
Route::resource('/views/cars', CarsController::class);
Route::resource('/cars', CarsController::class);
@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 but you don't have a / Route defined; you have only resource routes for http://127.0.0.1:8000/cars or http://127.0.0.1:8000/views/cars (depending on which one is defined). You can add a home route, so http://127.0.0.1:8000/ will work:
// routes/web.php
Route::get('/', function () {
return 'hello world';
});
Route::resource('/views/cars', CarsController::class);
@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
@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
@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
@yahia1001 are you able to get any Route to work? What is the result of php artisan route:list?
@tykus //imgur.com/a/AIGAARZ here is what i get
@yahia1001 Ok, and visiting http://127.0.0.1:8000/cars does not work???
@yahia1001 did you cache your routes by accident? php artisan route:clear
@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
@Sinnbeck no i do not rember running that command
@tykus i just run
php artisan servein 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!
@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
@yahia1001 I mean try running it. Stop the serve process, run the command and start serve again
@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
@Sinnbeck same result
@tykus so does he have a root defined and i do not that is why i get this error
@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
@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!)
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.