Tayyab
Tayyab

Reputation: 123

Class "app\models\category" not found in laravel 8

I am trying to get info from the database in the blade.php file(table) but the error pops-up. please tell me what I am doing wrong? I think the problem is in the index function. tried to debug but nothing. please tell me if you need more files to see. I'll send them quickly. sorry if this is a beginner question. I am a beginner :(

Controller

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use app\models\category;

class categorycontroller extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $cat = category::all();
        return view('categories')->with('categories',$cat);
    }

blade.php file

@extends ('layouts.admin')




@section('content')

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
</head>
<body>
<h1 class="bg-primary text-center text-white">Add category</h1>
<form action="{{route('categories.store')}}" method="post" enctype="multipart/form-data" class="w-75 mx-auto">
@csrf
<div class="form-group">
<label for="formgroupexampleinput">Title</label>
<input type="text" name="title" class="form-control" required>
</div>
<div class="form-group">
<label for="formgroupexampleinput">Image</label>
<input type="file" name="file" required >
</div>
<div class="form-group">
<label for="formgroupexampleinput">Description</label>
<input type="text" name="description" class="form-control" required >
</div>
<input type="submit" class="form-control btn-primary w-25" value="Submit">
</form>
<h1>Categoreis Data</h1>
<table class="table">
<tr>
<th>Title</th>
<th>Description</th>
<th>Edit</th>
<th>Delete</th>
</tr>
@foreach($categories as $cat)
<tr>
<td>{{$cat->title}}</td>
<td>{{$cat->description}}</td>
<td><a href="{{edit/{{$cat->id}}}}">Edit</a></td>
<td><a href="{{delete/{{$cat->id}}}}">Delete</a></td>
</tr>
@endforeach
</table>
</body>
</html>

@endsection

Upvotes: 0

Views: 1847

Answers (1)

Mallick
Mallick

Reputation: 26

Change the model name because the server consists of file names that are case sensitive. In your case use app\models\Category;

Upvotes: 1

Related Questions