2015-04-12 67 views
-1

我以前见过一些存储库的方法,其中开发人员有一个方法来检索字段以准备表单内的下拉列表。
这是我想用我的应用程序的优势。
这是我在多个实体的应用程序的多个区域中使用的逻辑。存储库方法对于Dropdowns

这是我想要的东西,但我无法得到它。

有人知道某处我能找到这个逻辑吗?

我已经做了一些研究,但是我还没有找到它。 但我在某处看过它。

+1

什么是你真正想要?你能提供一个实际的例子吗?很可能您需要设置您的存储库,并直接从控制器调用存储库中的方法(以便将其传递到视图中),否则您将使用服务处于控制器和存储库之间的“中间”。 –

回答

1

我终于遇到了一些帮助我的东西。我还为任何可能正在寻找类似内容的人提供了一个链接。

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); 
}