Php (E_错误)函数Symfony\Component\HttpKernel\Profiler\Profile的参数太少::u construct(),传递了0
我想使用关系归属和hasOne将概要文件模型与现有用户模型关联起来,我得到了这个错误 这是我的Profile.phpPhp (E_错误)函数Symfony\Component\HttpKernel\Profiler\Profile的参数太少::u construct(),传递了0,php,laravel,Php,Laravel,我想使用关系归属和hasOne将概要文件模型与现有用户模型关联起来,我得到了这个错误 这是我的Profile.php <?php namespace App; use Illuminate\Database\Eloquent\Model; class Profile extends Model { public function user(){ return $this->belongsTo(User::class); } } 若要解决
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
public function user(){
return $this->belongsTo(User::class);
}
}
若要解决此问题,请替换使用Symfony\Component\HttpKernel\Profiler\Profile;使用use App\Profile在User.php文件顶部的行;相反
这是因为您错误地将错误的类包含在User.php文件的顶部。当Laravel试图加载关系时,它会尝试构造一个Symfony\Component\HttpKernel\Profiler\Profile对象,而不是构造您想要的模型。在您的用户模型中使用下面的方法
public function profile()
{
return $this->hasOne('App\Profile', 'foreign_key');
}
我不知道您为什么在用户模型中使用Symfony\Component\HttpKernel\Profiler\Profile。当你的关系建立时,它使用的是那个档案,而不是你的档案模型。定义关系时必须使用概要文件模型命名空间
$user->profile
TypeError: Too few arguments to function Symfony/Component/HttpKernel/Profiler/Profile::__construct(), 0 passed in /Users/macair13/freeCodeGram/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php on line 720 and exactly 1 expected.
public function profile()
{
return $this->hasOne('App\Profile', 'foreign_key');
}