How do you reference a model in a laravel controller? -


this question exact duplicate of:

i'm finding distinction between "controller" , "model" in laravel 5.2 blurry.

i use artisan create restful controller, , in store method, try create new object.

// store in database $car = new app\models\carmodel; 

then error follows:

class 'carfreak\http\controllers\app\models\carmodel' not found 

so seems come down namespace of controller, don't understand it.

the name space describes controller, right? why reference model, being built on controllers path? shouldn't have it... right?

edit: after trying various suggestions, i've concluded there 3 things at:

  1. each class has namespace set, correctly describing folder class located
  2. in controller, have statement "use app\models\carmodel"
  3. refer model in controller.

each seems correct, still error cannot find model

this namespace problem in php.

you use this.

$car = new \app\models\carmodel; 

or

use app\models\carmodel; ....     class {     $car = new carmodel; } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -