ErrorException: неопределенная переменная: запрос в файле - PullRequest
0 голосов
/ 24 января 2020

Ошибка ErrorException: неопределенная переменная: запрос в файле всегда появляется, даже если я определил его как показано ниже

public function postlog_show(Request $request)
    {
        $log = $request->log;
        $userlocation = Auth::user()->location;
        $postlocations = Postlocation::orderBy('id', 'DESC')->where('location', $userlocation)
                ->whereHas('postlognya', function (Builder $query) {
                    $query->where('log', 'like', '%' . $request->log . '%');
                })
        ->get();

        return view('front.postlog2')
            ->with('postlocations', $postlocations)
        ;
    }

Ответы [ 2 ]

3 голосов
/ 24 января 2020

у вас будет use $request переменная в whereHas функции, как я показал

public function postlog_show(Request $request)
{
    $log = $request->log;
    $userlocation = Auth::user()->location;
    $postlocations = Postlocation::orderBy('id', 'DESC')->where('location', $userlocation)
            ->whereHas('postlognya', function (Builder $query) use($request){
                $query->where('log', 'like', '%' . $request->log . '%');
            })
    ->get();

    return view('front.postlog2')
        ->with('postlocations', $postlocations)
    ;
}
0 голосов
/ 24 января 2020

простое использование use($request)

whereHas('postlognya', function (Builder $query) use($request) {
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...