php - Resource routing

so I'm relatively new to laravel and am trying to understand it. So far it has been good but I've been stuck at an error for a while now so any help would be appreciated.
I'm trying to follow along with a youtube tutorial (not sure if links are allowed) and this is what I'm trying to do, I've a controller called, CarsController Inside my controllers file and a model named Car
I've generated the CarsController page by using the --resource flag, so inside my index function I've this code.
public function index()
{
return view('index'); //Error here, replace with return view (cars.index);
}
inside my web.php page for routing I've the following command
use App\Http\Controllers\CarsController; //added by me
use Illuminate\Support\Facades\Route; //present by default
Route::resource('/cars', CarsController::class);
As far as I understood from the documentation, using resource routing is better as I don't have to write the routes for every function that exists in my controller.
Also, the page I'm trying to view has a directory hierarchy of something like
resources > views > cars > index.blade.php
That is the file I'm trying to access. Sorry if this is a noob question by I've tried looking at the documentation and googling and don't understand what I'm doing wrong exactly.
Lastly, the error I'm receiving is a basic 404 one when accessing http://127.0.0.1:8000/. if I try accessing http://127.0.0.1:8000/cars I just get index is not a file are you the blade.php view exists. Also if it matters I've deleted the default welcome page file that laravel includes inside the views folder.
This is my route list through the PHP artisan command,
Edit: This is the documentation I'm, referring https://laravel.com/docs/8.x/controllers#resource-controllers
Edit2: My code for cars/index.blade.php
@extends('layouts.app')
@section() //error here too, replace with @section('content')
<div class="m-auto w-4/5 py-24">
<div class="text-center">
<h1 class = "text-5xl uppercase bold">
Cars
</h1>
</div>
</div>
@endsection
Im using tailwind CSS if it matters.
layouts/app.blade.php
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="{{ assset('css/app.css') }}">
<title>Document</title>
</head>
<body class="bg-gradient-to-r from gray-100 to-gray-200">
@yield('content')
</body>
</html>
Answer
Solution:
Your blade located atresources > views > cars > index.blade.php
,
so yourview()
method will beview('cars.index')
:
public function index()
{
return view('cars.index');
}
Answer
Solution:
Inside your method you can return the view asreturn view('cars.index');
where the index is the index.blade.php file inside the cars folder.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: warning: undefined array key
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.