A
A
alestro2016-05-05 19:41:51
Laravel
alestro, 2016-05-05 19:41:51

Laravel does not find the model class. How to fix?

The bottom line is this: I created a model using php artisan make:model Models\Game
Then I created the following service provider:

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class GameServiceProvider extends ServiceProvider
{
   protected $defer = true;
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind('Game', function($app)
    {
    	return new \App\Models\Game();
    });
    }
   public function provides()
    {
        return ['\App\Models\Game'];
    }

}

I registered it in the app.php config: App\Providers\GameServiceProvider::class
and I'm trying to access it in the route
Route::get('/', function () {
  $games=(new \app\models\Game())->all();
    return view('main',['games'=>$games]);
});

and I get this: Fatal error: Class 'app\models\Game' not found
tried using App:make('Game'); I get the following: Class 'APP' not found.
What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rustamka Vorontsov, 2016-05-05
@alestro

new \app\models\Game() -> new \App\Models\Game() not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question