Laravel 8 resource controller 404 not found

Viewed 770

Previous/same questions
But none of them worked
https://stackoverflow.com/questions/64332325/404-not-found-in-laravel-8\ Laravel 404 not found on resource

Trying to learn how to use Laravel Resource Controllers
https://laravel.com/docs/8.x/controllers#resource-controllers

I've encountering two different funny problem that:

  • Even the index exists still return 404 pages;

  • When I move index.blade.php to /app/views/ but the subside http://127.0.0.1:8000/cars shows correctly;

  • When I use route:clear and route:cache both side http://127.0.0.1:8000 nor http://127.0.0.1:8000/cars work and became 404 pages;

The codes:
web.php:

<?php

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

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

index.blade.php

<H2>#resource-controllers</H2>

CarsController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class CarsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('index');
    }

and the last I've check the route:list

+--------+-----------+---------------------+-----------------------------+------------------------------------------------------------+------------------------------------------+
| Domain | Method    | URI                 | Name                        | Action                                                     | Middleware                               |
+--------+-----------+---------------------+-----------------------------+------------------------------------------------------------+------------------------------------------+
|        | GET|HEAD  | api/user            | generated::aTHAYl9kwyoN9YZ4 | Closure                                                    | api                                      |
|        |           |                     |                             |                                                            | App\Http\Middleware\Authenticate:sanctum |
|        | GET|HEAD  | cars                | cars.index                  | App\Http\Controllers\CarsController@index                  | web                                      |
|        | POST      | cars                | cars.store                  | App\Http\Controllers\CarsController@store                  | web                                      |
|        | GET|HEAD  | cars/create         | cars.create                 | App\Http\Controllers\CarsController@create                 | web                                      |
|        | GET|HEAD  | cars/{car}          | cars.show                   | App\Http\Controllers\CarsController@show                   | web                                      |
|        | PUT|PATCH | cars/{car}          | cars.update                 | App\Http\Controllers\CarsController@update                 | web                                      |
|        | DELETE    | cars/{car}          | cars.destroy                | App\Http\Controllers\CarsController@destroy                | web                                      |
|        | GET|HEAD  | cars/{car}/edit     | cars.edit                   | App\Http\Controllers\CarsController@edit                   | web                                      |
|        | GET|HEAD  | sanctum/csrf-cookie | generated::7247C9D8SwAaVWdO | Laravel\Sanctum\Http\Controllers\CsrfCookieController@show | web                                      |
+--------+-----------+---------------------+-----------------------------+------------------------------------------------------------+------------------------------------------+

I'm still trying to find any kinds solution of this, but so far couldn't figure out which part went wrong.

wrong place index.blade.php but shows pages

2 Answers

Try: Route::get("/cars",[CarsController::class,'index']);

This would be a minor mistake

about the address port setting

I've change the log-in account while debug-ing

after few days change the

http://127.0.0.1:8000/cars to http://127.0.0.1:8001/cars

the blade.index.php shows the specific page path correctly

Related