4 months ago

Database Queries in Model or Controller

Posted 4 months ago by repulsor

I am very new to Laravel, learning new things everyday and wants to do things the right way than being hacky.

I am trying to fetch user roles from Roles table. I have a controller, which has function which needs the roles data and then it feeds it to the view.

I have a model for the roles table.

How do I put the codes?

A function in model,which pulls the data, which is called from the controller? (Wont that make a call to itself like this?)

Role Model

   public function fetchroles(){
    return Role::select('role_id','type')



Something like

public static function addstaff(){
    //Fetch Staff Roles
$roles = Call to Model function. ( I dont know how)

Please put light so I can learn :)

Please sign in or create an account to participate in this conversation.