public function qualifyCollectionQuery($query)
    {
        $user = auth()->user();

        $modelPolicy = Gate::getPolicyFor(static::$model);

        // If no policy exists for this model, then there's nothing to check
        if (is_null($modelPolicy)) {
            return $query;
        }

        // Add conditions to the query, if they are defined in the model's policy
        if (method_exists($modelPolicy, 'qualifyCollectionQueryWithUser')) {
            $query = $modelPolicy->qualifyCollectionQueryWithUser($user, $query);
        }

        return $query;
    }
public function qualifyCollectionQuery($query)
    {
        $user = auth()->user();

        $modelPolicy = Gate::getPolicyFor(static::$model);

        // If no policy exists for this model, then there's nothing to check
        if (is_null($modelPolicy)) {
            return $query;
        }

        // Add conditions to the query, if they are defined in the model's policy
        if (method_exists($modelPolicy, 'qualifyCollectionQueryWithUser')) {
            $query = $modelPolicy->qualifyCollectionQueryWithUser($user, $query);
        }

        return $query;
    }
public function qualifyCollectionQuery ( $ query ) { $ user = auth ( ) -> user ( ) ; $ modelPolicy = Gate :: getPolicyFor ( static :: $ model ) ; // If no policy exists for this model, then there's nothing to check if ( is_null ( $ modelPolicy ) ) { return $ query ; } // Add conditions to the query, if they are defined in the model's policy if ( method_exists ( $ modelPolicy , 'qualifyCollectionQueryWithUser' ) ) { $ query = $ modelPolicy -> qualifyCollectionQueryWithUser ( $ user , $ query ) ; } return $ query ; }
This function can be used to add conditions to the query builder,
which will specify the currently logged in user's ownership of the model

@param \Illuminate\Database\Eloquent\Builder $query
@return \Illuminate\Database\Eloquent\Builder|null
This function can be used to add conditions to the query builder which will specify the currently logged in user s ownership of the model