无法识别的阶级 - 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

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.

it's normal the class Pain not found, check what you done here :

php artisan make:model paint

and on your routes file :

$paintings = new Paint;

try to correct your model class name to this Paint , and when you want to instanciate it don't forget the namespace by default for the generated model class , so you routes file will look like this

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

});