【发布时间】:2020-04-22 07:41:18
【问题描述】:
我是 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 Error: Call to undefined method stdClass::save() in Psy Shell code on line 1
这里是我的 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();
});
}
提前致谢
【问题讨论】:
标签: laravel phpstorm laravel-artisan laravel-6 tinker