2
私は、ユーザがmembers()モデルの中にいる場合、ログインユーザに従ってプロジェクトリストをフィルタリングする必要があるこの条件を持っています。Laravelでモデルを使ってどこで行うのですか?
public function index(Request $request = null, $search = null)
{
$user = $this->user;
$data = project_registry::with('members', 'members.profile')->where('isdelete', 0);
if(!$user->project_view) {
// here i need to do the filter for the login user to view project where they are the member of the project
}
if(!is_null($request['search'])) {
$search = $request['search'];
$data->where(function($q) use ($search) {
$q->where('Project_Code', 'LIKE', "%$search%")->orWhere('Project_Short_name', 'LIKE', "%$search%");
});
}
$data = $data->orderBy('Project_ID')->paginate(20);
return view('project.index', compact('data', 'search'));
}
うわー...それは便利です。ありがとう;) –
正式な[laravel doc](https://laravel.com/docs/5.3/eloquent-relationships)にある – amow
ええ..私はそれを見落としました。 Btw tq –