
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
- Validation for multiple forms on same page in laravel
- How to check data inserted or deleted in pivot after toggle method
- Send OTP using textlocal api in laravel
- How to pass data to partial view file in laravel
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- Credit card validation in laravel
- How to create projects method with belongstomany relationship in user model
- SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'user_id'
- How to add foreign key in laravel using migration
- Always load the relationship data with eager loading in Laravel
- Call to a member function pluck() on array
- How to send email in laravel
- How to upload image in laravel 8
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Multiple Level eager loading in Laravel
- Add a subselect based on relationship using withAggregate method
- How to send ID to another page in Laravel
- How to get the id of last record from collection object in laravel view
- Page loader in laravel
- Laravel append URI in route
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- How to get user information using hootlex/laravel-friendships package in laravel
- Return view from route Laravel
- How to increment column value of table in Laravel
- Get current URL on visit URL in Laravel