I've previously seen some methods for repositories where developers have a method for retrieving fields for preparing dropdowns inside of a form.
This is something I'd like to take advantage of with my application.
This is the logic that I would use in multiple areas of my app for multiple entities.
It's something I want, but I can't get it.
Does anyone know of somewhere I can find this logic?
I've done some research, but I have not found it yet. But I've seen it, somewhere.
I finally came across something that helped me. I've also included a link for anyone that might be looking for something like this.
http://blog.dannyweeks.com/web-dev/repositories-in-laravel-sharing-my-base-repository
/**
* Items for select options
* @param string $data column to display in the option
* @param string $key column to be used as the value in option
* @param string $orderBy column to sort by
* @param string $sort sort direction
* @return array array with key value pairs
*/
public function getForSelect($data, $key = 'id', $orderBy = 'created_at', $sort = 'DECS')
{
return $this->model
->with($this->relationships)
->orderBy($orderBy, $sort)
->lists($data, $key);
}