
Call to a member function pluck() on null
We got the error call to a member function pluck() on null, when we called pluck method on null. So before calling pluck method check if the variable is empty or not after that call pluck method else it will return an error message call to a member function pluck() on null.
-
Call pluck method on $user->followings to get followings in Overtrue\LaravelFollow
$user = Auth::user(); if($user->followings){ $followings = $user->followings->pluck('id'); }else{ $followings = array(); } $users = User::whereNotIn('id', $followings) ->where('id', '<>', $user->id) ->get();
0In my case I have called the $user->followings->pluck(‘id’) to the whereNotIn() query and got the error because there are no followings for the logged in user in the table. So the $user->followings method returns the null value so that is why we got the error calling a member function pluck() on null.
After that i have checked following if it is null then we pass empty array to pluck method
Random Code Snippet Queries: Laravel
- How to use more than one query scope in Laravel
- Pass variable from blade to controller Laravel
- Run artisan command to generate key in laravel
- How to get query string value in laravel
- Create model with migration and seeder
- Class "App\Http\Controllers\Auth\Verified" not found
- How to Get records between two dates in Laravel
- How to authenticate admin users in Laravel ?
- Cannot end a section without first starting one
- Permission denied error while creating storage link in Laravel
- Delete file from amazon s3 bucket using Laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Display data in table using foreach in Laravel
- How to decrypt laravel password
- If condition in foreach loop in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- Laravel form request validation
- Get current URL on visit URL in Laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- OrderBy on Eloquent relationships method in Laravel
- How to pass external link in laravel blade to anchor tag
- How to get random string in Laravel
- Insert current date time in a column using Laravel
- How to change default timestamp fields name in Laravel