[英]Retrieve data through user_Id
I'm building an API of a profile. 我正在构建配置文件的API。 That is my profile controller and I want to retrieve data from the User with the Profile.
那是我的配置文件控制器,我想使用配置文件从用户检索数据。 I'm using
OneToOne
relationships. 我正在使用
OneToOne
关系。 I want to retrieve data for the single user but as you can see it will give me the data of total users so how can I retrieve of the related user based on id or profile id. 我想检索单个用户的数据,但是如您所见,它将为我提供总用户的数据,因此我如何根据ID或个人资料ID检索相关用户。
profileController extends Controller
{
public function setting(){
$profile=User::with('profile')->get();
return $profile; `enter code here`
}
}`
profileController extends Controller
{
public function setting(){
$profile=User::with('profile')->where('user_id',$user_id)->first();
return $profile; `enter code here`
}
user where() and first() 用户where()和first()
you can try this: 您可以尝试以下方法:
profileController extends Controller
{
public function setting(){
$profile=User::table('profile')->where('user_id',$user_id)->get();
return view('profile_page',['profile' => $profile]);
// or
return view('profile_page')->with('profile' => $profile);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.