Laravel PHP错误:在第1行的Psy Shell代码中调用未定义的方法stdClass::save()

Laravel PHP错误:在第1行的Psy Shell代码中调用未定义的方法stdClass::save(),laravel,phpstorm,laravel-artisan,laravel-6,tinker,Laravel,Phpstorm,Laravel Artisan,Laravel 6,Tinker,我是新来的拉威尔人, 我正在使用tinker创建一个记录: $Profile=new \App\Profile(); => App\Profile {#3038} >>> $profile->title='Premier Titre' PHP Warning: Creating default object from empty value in Psy Shell code on line 1 >>> $profile->title='P

我是新来的拉威尔人, 我正在使用tinker创建一个记录:

$Profile=new \App\Profile();
=> App\Profile {#3038}
>>> $profile->title='Premier Titre'
PHP Warning:  Creating default object from empty value in Psy Shell code on line 1
>>> $profile->title='Premier Titre';
=> "Premier Titre"
>>> $profile->description='Description';
=> "Description"
>>> $profile->user_id=1;
=> 1
>>> $profile->save()
PH
我有以下错误:PHP错误:在Psy Shell代码的第1行调用未定义的方法stdClass::save()

这里是my profile.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Profile extends Model
{
    public function user()

{
    return $this->belongsTo(User::class );
}
}

提前感谢

这里的问题是您用大写字母定义变量:

$Profile=new \App\Profile(); 
后来你把它和小写字母一起使用

$profile->title='Premier Titre'
因此,可能会创建新的stdClass对象,显然它没有
save
方法。您还将收到以下警告:

PHP警告:从Psy外壳代码第1行的空值创建默认对象

也就是说新的对象被创建了

所以一定要换衣服

$Profile=new \App\Profile(); 
进入


要使其工作

这里的问题是您使用大写字母定义变量:

$Profile=new \App\Profile(); 
后来你把它和小写字母一起使用

$profile->title='Premier Titre'
因此,可能会创建新的stdClass对象,显然它没有
save
方法。您还将收到以下警告:

PHP警告:从Psy外壳代码第1行的空值创建默认对象

也就是说新的对象被创建了

所以一定要换衣服

$Profile=new \App\Profile(); 
进入

让它工作起来