Laravel CRUD ORM 找不到模型
Laravel CRUD ORM Can't find model
我一直在尝试将用户与配置文件相关联。
这是我的代码:
资料模型:
class Profile extends Model
{
public function user(){
return $this->belongsTo('App\User');
}
}
用户模型:
class User extends Authenticatable
{
...
public function profile(){
return $this->hasOne('App/Profile');
}
}
配置文件控制器:
public function show($username)
{
$user = User::where('username',$username)->first();
$profile = $user->profile;
return view('profiles.show')->withProfile($profile);
}
路线(本来是"profil"):
Route::resource('profil','ProfileController');
非常欢迎任何有关执行其余 CRUD 功能的提示!
在您的 User
模型关系中将 App/Profile
更改为 App\Profile
。
我一直在尝试将用户与配置文件相关联。 这是我的代码:
资料模型:
class Profile extends Model
{
public function user(){
return $this->belongsTo('App\User');
}
}
用户模型:
class User extends Authenticatable
{
...
public function profile(){
return $this->hasOne('App/Profile');
}
}
配置文件控制器:
public function show($username)
{
$user = User::where('username',$username)->first();
$profile = $user->profile;
return view('profiles.show')->withProfile($profile);
}
路线(本来是"profil"):
Route::resource('profil','ProfileController');
非常欢迎任何有关执行其余 CRUD 功能的提示!
在您的 User
模型关系中将 App/Profile
更改为 App\Profile
。