doubaoguo7469 2015-10-06 21:55
浏览 62
已采纳

无法识别的阶级 - laravel Eloquent Model

I am trying to update my database using Eloquent model but the class is not recognized.

First I created my table using migration and that worked fine.. Below is the code use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

class CreatePaintings extends Migration
{
/**
 * Run the migrations.
 *
 * @return void
 */
 public function up()
 {
    Schema::create('paintings',function($thepainting){
            $thepainting->increments('id');
            $thepainting->string('title');
            $thepainting->string('artist');
            $thepainting->integer('year');
            $thepainting->timestamps();

    });
 }

 /**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('paintings');
}
}

Next, I created a class "paint" using the model. But note that the recent version of laravel don't have the model folder specified explicitly. So when I ran the code below on the command prompt I was able to create the paint class

php artisan make:model paint

Lastly, I tried updating the created table, paintings, via routes.php using the code below..

Route::get('/', function() 
{
$paintings = new Paint;
$paintings->title = 'Emmanuel';
$paintings->artist = 'D. DoRight';
$painitngs->year = 2014;
$paintings->save();

return view('trynn');

});


 Route::get('about/directions', function() 
 {
 return "Direction content goes here";
  });

 Route::get('about/{theSubject}', function($theSubject) 
  {  
  return $theSubject. " content goes here";

  });

please I am new to laravel, so I will appreciate any help to get this resolved. I am presently stranded. Lest I forget, The error message is shown below


Whoops, looks like something went wrong.

1/1 FatalErrorException in routes.php line 18: Class 'Paint' not found

in routes.php line 18

  • 写回答

2条回答 默认 最新

  • 普通网友 2015-10-06 22:09
    关注

    Ah, this is a simple error. Can you copy-paste the whole content of the file in if that is not all of it.

    Also the error for this is because you haven't brought in the class from the autoloader. In Laravel, everything is namespaced. In your Paint Model, at the top you will see namespace App, if you moved the Paint model into say a models directory, you need to namespace the class App\Models;

    To fix this error, at the top of the routes.php file, write use App\Paint;. But you should really send that route to a controller to separate the code from the routes.

    Let me know if that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀