<?php /** * Created by PhpStorm. * User: liuxiang * Date: 16/6/22 * Time: 17:06 */ return [ 'directory_path' => 'App'.DIRECTORY_SEPARATOR.'Repositories', 'directory_eloquent_path' => 'App'.DIRECTORY_SEPARATOR.'Repositories'.DIRECTORY_SEPARATOR.'Eloquent', 'repository_namespace' => 'App\Repositories\Eloquent', 'repository_interface_namespace' => 'App\Repositories', ];
运行一下看可不可以吧,这里截个图:
It is working!!!
是可以生成RepositoryInterface和对应的接口实现文件,这里一个是加了--model选项一个没加的,没加的话这里第一个指令就默认Model的名称是Shop。
生成的文件内容不截图了,看下新生成的ShopRepository.php文件,的确是我想要的模板文件:
<?php /** * Created by PhpStorm. * User: liuxiang */ namespace App\Repositories\Eloquent; use App\Shop; use App\Repositories\ShopRepositoryInterface; class ShopRepository implements ShopRepositoryInterface { /** * @var \App\Shop */ public $shop; public function __construct(Shop $shop) { $this->shop = $shop; } /** * @param array $columns * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function all($columns = array('*')) { return $this->shop->all($columns); } /** * @param int $perPage * @param array $columns * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator */ public function paginate($perPage = 15, $columns = array('*')) { return $this->shop->paginate($perPage, $columns); } /** * Create a new shop * @param array $data * @return \App\Shop */ public function create(array $data) { return $this->shop->create($data); } /** * Update a shop * @param array $data * @param $id * @return \App\Shop */ public function update($data = [], $id) { return $this->shop->whereId($id)->update($data); } /** * Store a shop * @param array $data * @return \App\Shop */ public function store($data = []) { $this->shop->id = $data['id']; //... $this->shop->save(); } /** * Delete a shop * @param array $data * @param $id * @return \App\Shop */ public function delete($data = [], $id) { $this->shop->whereId($id)->delete(); } /** * @param $id * @param array $columns * @return array|\Illuminate\Database\Eloquent\Collection|static[] */ public function find($id, $columns = array('*')) { $Shop = $this->shop->whereId($id)->get($columns); return $Shop; } /** * @param $field * @param $value * @param array $columns * @return \Illuminate\Database\Eloquent\Collection|static[] */ public function findBy($field, $value, $columns = array('*')) { $Shop = $this->shop->where($field, '=', $value)->get($columns); return $Shop; } }