简体   繁体   English

找不到 Laravel 雄辩的模型类

[英]Laravel eloquent model Class not found

This is my web.php in routes folder这是我在路由文件夹中的 web.php

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

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

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

This is my Task model, Task.php这是我的任务模型,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我不知道为什么当我去 /task 时,显示错误

Class 'App\\Task' not found未找到“应用\\任务”类

Can someone help me?有人可以帮助我吗? I am new to Laravel我是 Laravel 的新手

Top of your web.php route file mention model您的 web.php 路由文件顶部提及模型

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这是您的修复,您的模型名称为Tasks而不是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.另一个可能对其他人有帮助的可能解决方案是模型文件的文件名中没有 .php。 So in this case the model filename would be Task instead of Task.php所以在这种情况下,模型文件名将是 Task 而不是 Task.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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