Call to a member function pluck() on null
Call to a member function pluck() on null
In this session, we’ll try our hand at solving the "Call to a member function pluck() on null" puzzle by using the computer language.
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();
In 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
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Check if Relationship Method Exists in Laravel
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- Laravel specific table Migration
- Add a subselect based on relationship using withAggregate method
- Eager loading dynamically in laravel
- In order to use the Auth::routes() method, please install the laravel/ui package
- Laravel hasmany select not working
- Return view from route Laravel
- How to insert ckeditor data into database in Laravel?
- Laravel 7 login error message not showing
- Get last record from table in laravel
- Laravel 11 step by step instructions to upload file in storage directory and display in blade file
- Laravel pagination links with query string
- Get content from web URL in laravel
- If condition in Laravel 9
- Get laravel version
- How to upload image in laravel 8
- Get the post details if it has at least one comment in comments table
- How to create event and listener in laravel ?
- Class 'App\Providers\Auth' not found
- Include External CSS and JS file in Laravel
- How to get CSRF token in laravel controller
- How to pass data to multiple partial view files in laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- OrderBy on Eloquent relationships method in Laravel