php - Laravel not an object -


im trying use _construct in laravel bellow code

class songscontroller extends controller {      private $song;      public function _construct(song $song){          $this->song=$song;     }     public function index()     {         $songs=$this->song->get();         return view('songs',compact('songs'));     }   } 

but in line: $songs=$this->song->get(); error: call member function get() on non-object. wrong? btw run perfect if this:

public function index(song $song)     {         $songs=$song->get();         return view('songs',compact('songs'));     } 

as @federico noted in comments proper syntax php constructers double underscore __ not _:

public function __construct(song $song) {     $this->song=$song; } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -