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.phpto/app/views/but the subsidehttp://127.0.0.1:8000/carsshows correctly;When I use
route:clearandroute:cacheboth sidehttp://127.0.0.1:8000norhttp://127.0.0.1:8000/carswork 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.