I have say simple example of getting an object using this query:
return App\models\SuccessIndicatorYearWeight::find(1);
This returns:
{
success_indicator_year_weight_id: "108",
success_indicator_id_fk: "174",
year_id_fk: "1",
criteria_excel: "05-05-2015",
criteria_very_good: "08-05-2015",
criteria_good: "11-05-2015",
criteria_fair: "15-05-2015",
criteria_poor: "20-05-2015",
created_by: "4",
create_date: "2015-05-01 21:40:35",
updated_by: "4",
update_date: "2015-05-02 06:49:30",
}
Now I want to return only these properties from the object, criteria_excel, criteria_very_good, criteria_fair, criteria_poor.
I have tried with these:
return App\models\SuccessIndicatorYearWeight::find(1)->pluck('criteria_excel', 'criteria_very_good', 'criteria_fair', 'criteria_poor');
And
return App\models\SuccessIndicatorYearWeight::find(1)->select('criteria_excel', 'criteria_very_good', 'criteria_fair', 'criteria_poor')->get();
And was unsuccessful.
A simple workaround is this:
return App\models\SuccessIndicatorYearWeight::whereId(1)->select('criteria_excel', 'criteria_very_good', 'criteria_good', 'criteria_fair', 'criteria_poor')->get();
But, I was wondering if there are any other ways to return only selected properties of an object.