Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 问:如何在Laravel中按用户名显示、更新和编辑用户配置文件?_Php_Laravel - Fatal编程技术网

Php 问:如何在Laravel中按用户名显示、更新和编辑用户配置文件?

Php 问:如何在Laravel中按用户名显示、更新和编辑用户配置文件?,php,laravel,Php,Laravel,我有一个定制的身份验证保护申请人,并且已经创建了申请人配置文件模型 问题1: 到目前为止,我一直在使用show方法,它正在工作,但是无论我传递到哪个路径,它都会呈现视图 问题2: 我想通过每个申请人的ID 问题3: 如何编辑和更新经过身份验证的用户配置文件 配置文件模型 class ApplicantsProfile extends Model { protected $fillable = [ 'job_title', 'applicant_id', ];

我有一个定制的身份验证保护
申请人
,并且已经创建了
申请人配置文件
模型

问题1:

到目前为止,我一直在使用show方法,它正在工作,但是无论我传递到哪个路径,它都会呈现视图

问题2:

我想通过每个申请人的
ID

问题3:

如何编辑和更新经过身份验证的用户配置文件

配置文件模型


class ApplicantsProfile extends Model
{
    protected $fillable = [
        'job_title', 'applicant_id',
    ];

    public function applicant()
    {
        return $this->belongsTo(Applicant::class);
    }
}

Profile Controller


class ApplicantsProfileController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth:applicant');
    }

    public function show($id)
    {
       $profile = ApplicantsProfile::find($id);

       return view('applicant.profile', compact('profile'));
    }
}

纵断面图

@extends('layouts.auth')

@section('content')
<div class="container">
  <div class="row justify-content-center">
    <div class="col-md-5">
      <div class="card">
        <div class="card-header">{{Auth::guard('applicant')->user()->name}}</div>

        <div class="card-body">
          {{Auth::guard('applicant')->user()->profile->job_title}}
        </div>
      </div>
    </div>
  </div>
</div>

@endsection

如果我转到route:account/1或account/2,它将呈现经过身份验证的用户的视图。

在您的配置文件视图中,您使用
Auth
,因此显示这些结果是正常的。 您必须将视图刀片修改为以下内容:

@extends('layouts.layout')

@section('content')
<div class="container">
  <div class="row justify-content-center">
    <div class="col-md-5">
      <div class="card">
        <div class="card-header">
            {{ $applicantsProfile['name'] }}
        </div>
        <!-- complete your code like so -->
在web.php路径中:

Route::get('/account/{applicantsProfile}', 'ApplicantsProfileController@show');

它可以工作,但是访问与用户表相关的电子邮件地址又如何呢?还是将所有用户信息存储在用户模型中而不是在我的案例中使用单独的模型是一种更好的方法
应用程序配置文件
?这取决于您的应用程序所有应用程序都没有绝对答案,但我的建议是尽可能简单。如果用户模型对于您的应用程序来说足够了,那么就不需要额外的支持,谢谢:)
 public function show(ApplicantsProfile $applicantsProfile)
    {
       return view('applicant.profile', compact('applicantsProfile'));
    }
Route::get('/account/{applicantsProfile}', 'ApplicantsProfileController@show');