1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

laravel repositoryパターン 他のrepositoryを使いたいとき

Last updated at Posted at 2019-11-14
class AAController extends BaseController
{

    protected $externalImageRepository;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(
        Request $request,
        ComicTrialRepositoryInterface $comicTrialRepository,
        ExternalImageRepositoryInterface $externalImageRepository,
  ここ->  StaffRepositoryInterface $staffRepositoryInterface
    ) {
        parent::__construct($request);

        $this->repository = $comicTrialRepository;
        $this->externalImageRepository = $externalImageRepository;
 ここ->  $this->staffRepository = $staffRepositoryInterface;
    }
.
.
.
.
.

public function index(Request $request <--いらない)
    {
        // $requestParams = $request->all(); //取得データ用のパラメータ
  ここ-> $requestParams = $this->request->all(); //取得データ用のパラメータ

        unset($requestParams['page']);
        $params = $requestParams; // viewに受け渡す用のパラメータ

        if (isset($requestParams['assigned_user_id']) && $requestParams['assigned_user_id'] == 'all') {
            unset($requestParams['assigned_user_id']);
        }

        if (isset($requestParams['q']) && $requestParams['q'] == null) {
            unset($requestParams['q']);
        }

//        $staffList = $this->repository->staffList()->pluck('name', 'id')->toArray();
ここ->     $staffList = $this->staffRepository->getStaffList()->where('group', 'comic')->pluck('name', 'id')->toArray();
//        dd($staffList);

        $comicTrialPager = $this->repository->getPager($requestParams);

        return view('comic_trial.index', compact('comicTrialPager', 'params', 'staffList'));
    }

・__construct() で Requestのセットしているので、ここで引数にしなくていい
・$this->repository->staffList()
comic_trial の関連テーブル以外の取得をComicTrialRepositoryを使わない。
StaffRepositoryを使う。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?