简体   繁体   中英

Laravel eloquent model Class not found

This is my web.php in routes folder

Route::get('/task',function(){

        $task = App\Task::all();

        return view('task',['task' => $task]);
    });

This is my Task model, Task.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Tasks extends Model
{
    //

}

I dont know why when i go /task , an error shown

Class 'App\\Task' not found

Can someone help me? I am new to Laravel

Top of your web.php route file mention model

use App\Task;

and then use

Route::get('/task',function(){

        $task = App\Task::all();

        return view('task',['task' => $task]);
    });

Here is your fix, you have model with name Tasks not Task

$task = App\\Tasks::all();

Hope this helps

use App\Task;
add it in your controller where you want to fetch data

Another possible solution that might help others is that the model file doesn't have .php in the filename. So in this case the model filename would be Task instead of Task.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM