我是 Laravel 的新手,我正在使用 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 错误:在第 1 行的 Psy Shell 代码中调用未定义的方法 stdClass::save()
这是我的profile.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
public function user()
{
return $this->belongsTo(User::class );
}
}
这是我的迁移代码:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('surname')->unique();
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
提前致谢