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:
- each class has namespace set, correctly describing folder class located
- in controller, have statement "use app\models\carmodel"
- 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
Post a Comment