下拉列表的存储库方法
Repositories Method For Dropdowns
我以前见过一些用于存储库的方法,其中开发人员有一种方法来检索用于在表单内准备下拉列表的字段。
这是我想在我的应用程序中利用的东西。
这是我将在我的应用程序的多个区域中用于多个实体的逻辑。
这是我想要的东西,但我得不到。
有谁知道我在哪里可以找到这个逻辑?
我做了一些研究,但我还没有找到它。
但我在某处看到过它。
我终于找到了对我有帮助的东西。我还为可能正在寻找类似内容的任何人提供了 link。
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);
}
我以前见过一些用于存储库的方法,其中开发人员有一种方法来检索用于在表单内准备下拉列表的字段。
这是我想在我的应用程序中利用的东西。
这是我将在我的应用程序的多个区域中用于多个实体的逻辑。
这是我想要的东西,但我得不到。
有谁知道我在哪里可以找到这个逻辑?
我做了一些研究,但我还没有找到它。 但我在某处看到过它。
我终于找到了对我有帮助的东西。我还为可能正在寻找类似内容的任何人提供了 link。
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);
}