Creating default object from empty value - Laravel 5
Ad
I dont know how fix this error, my code:
$subscriptions = Auth::user()->subscriptions;
foreach($subscriptions as $subscription)
{
$subs = Subscription::find($subscription->id);
$subs->subscriptionstatus_id = 0;
$subs->save();
}
and laravel response with Creating default object from empty value
in line when I assign 0
, what can I do?
thanks
Ad
Answer
Ad
This was because the variable $subs
is null, and needs to check if has something:
$subscriptions = Auth::user()->subscriptions;
foreach($subscriptions as $subscription)
{
$subs = Subscription::find($subscription->id);
// Check if exist the subs record
if (count($subs) > 0)
{
$subs->subscriptionstatus_id = 0;
$subs->save();
}
}
I was added that validation and work's fine.
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad