Wednesday, March 1, 2017

Order list of records in Model method

I have a model called "Survey", and inside of it i have a method called "steps".

 public function steps(){
        return $this->hasMany(StepSurvey::class);
    }

Basically i have a relation between the survey table and other called step_surveys. In my method i need beside getting all steps order by desc using a column called "position", how can i accomplishe to change my method on the model?

Table:

step_surveys:
- id;
- survey_id;
- step_name
- position;




via Pedro

Advertisement