PHP error with variable in callback function

前端 未结 1 1719
伪装坚强ぢ
伪装坚强ぢ 2021-01-21 15:41

I have this function in php (laravel):

    public static function isUserParticipatesInTournament($tourId, $userId)
    {
        var_dump($userId); //dumped
             


        
相关标签:
1条回答
  • 2021-01-21 16:02

    Your $tourId variable is not in the scope of your anonymous function. Have a look at the use keyword to see how you can add it to the scope. See example 3 on this page: http://www.php.net//manual/en/functions.anonymous.php

    It should look something like the following:

    $obj = $user->whereHas('tournaments', function($query) use($tourId)
        {
            var_dump($tourId); // Dumps OK
        })->get();
    
    0 讨论(0)
提交回复
热议问题