php - how to run method in model instead of controller in laravel 5.1? -


i have following method in controller:

public function store() {     $data=input::all();     user::create($data); } 

the above code works perfectly. question can run above method in model without writing in controller? , best approach?

you can try following way

in model

public function insetuser() {         $input = input::all();         user::create($input);     //here instead of user,you can use self  self::create($input); } 

in controller can

public function store() {     user::insetuser(); } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -