I am working on someone else code in a Project and when I try to run the php artisan migrate I am encountering an error!
class SeedAdminUser extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// seed admin user
$admin = User::create([
'name' => 'Admin',
'email' => 'admin@admin.se',
'password' => Hash::make('password'),
'plan_id' => null,
]);
$admin->assignRole(['administrator', 'company']);
$plan = Plan::find(1);
Subscription::create([
'user_id' => 1,
'plan_id' => $plan->id,
'starts_at' => Carbon::now(),
'ends_at' => $plan->interval == 'monthly' ? Carbon::now()->addMonth() : Carbon::now()->addMonths(12),
]);
}
I am getting an error because of this line 'plan_id' => $plan->id,
Here is the Error message -
ErrorException
Trying to get property 'id' of non-object
at database/migrations/2021_06_04_055759_seed_admin_user.php:34
30|
31| $plan = Plan::find(1);
32| Subscription::create([
33| 'user_id' => 1,
> 34| 'plan_id' => $plan->id,
35| 'starts_at' => Carbon::now(),
36| 'ends_at' => $plan->interval == 'monthly' ? Carbon::now()->addMonth() : Carbon::now()->addMonths(12),
37| ]);
38| }
1 database/migrations/2021_06_04_055759_seed_admin_user.php:34
Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Trying to get property 'id' of non-object", "/Applications/MAMP/htdocs/iSurvey/database/migrations/2021_06_04_055759_seed_admin_user.php", [Object(App\User)])
+21 vendor frames
23 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
Any Idea what is wrong with that line 'plan_id' => $plan->id, and how to fix it