I'm alway doing the same thing with some of my models. I get list of all models as [id => name] array. I need that to display them in drop-down list in other's models crud to set relations. How can I put one static method in one place that would be available from any model? Now I have to write this code everywhere:
public static function getModelNameList()
{
return self::select('id','name')->get()->mapWithKeys(function ($model){
return [$model->id => $model->name];
})->toArray();
}
and then
$list = ModelName::getModelNameList();