
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
- Rendering HTML from database table to view in Laravel
- Get 30 days older records from table in laravel
- Class 'App\Rules\Hash' not found in Laravel
- How to get specific columns using with method in laravel Eloquent relationship
- How to create belongstomany relation using custom name on custom pivot table
- How to check query string exists or not in laravel blade
- How to get route name on visit URL in laravel
- Get today records in Laravel
- Display first n record from collection in laravel view
- Laravel append URI in route
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- Display data in table using foreach in Laravel
- How to return a column with different name in Laravel
- How to insert value to additional columns in pivot table in laravel
- Laravel route redirect not working
- Trying to access array offset on value of type null error in laravel
- Illuminate\Database\QueryException could not find driver
- Conditional where clause in Laravel
- Send post data from controller to view
- Create project table with model and migration
- How to run a specific seeder class in laravel
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- Include External CSS and JS file in Laravel
- Call to a member function getRelationExistenceQuery() on array in Laravel
- How to pass external link in laravel blade to anchor tag