Laravel 如何在#myTickets div中显示注册信息?
我有一个页面“”,用户可以在其中编辑与其帐户相关的内容。此页面的路径为:Laravel 如何在#myTickets div中显示注册信息?,laravel,Laravel,我有一个页面“”,用户可以在其中编辑与其帐户相关的内容。此页面的路径为: Route::get('/user/profile', [ 'uses' => 'UserController@index', 'as' =>'user.index' ]); 在UserController的index方法中,仅返回视图: public function index(){ return view('users.index')->with('user'
Route::get('/user/profile', [
'uses' => 'UserController@index',
'as' =>'user.index'
]);
在UserController的index方法中,仅返回视图:
public function index(){
return view('users.index')->with('user', Auth::user());
}
在此页面()中,有一些选项卡可以编辑/管理用户帐户的不同方面(常规信息、登录信息、我的票据)
怀疑:
我的疑问是在“#myTickets”选项卡中,我想显示用户的注册。所以我在UserController中创建了一个方法,如下所示。我的疑问是,当单击“我的票证”选项卡时,如何正确调用此方法来显示此信息,以及如何根据路线处理此问题。因为实际上没有使用getRegistrations方法
public function getRegistrations(){
$user = Auth::user();
$registrations = User::find($user->id)->registrations;
dd($registrations);
return view('users.index')->with('registrations', $registrations);
}
//选项卡链接
<ul class="nav nav-pills bg-light-gray account_options" role="tablist">
<li class="">
<a class="nav-link active" href="#generalInfo" data-toggle="tab" role="tab">
<i class="fa fa-user" aria-hidden="true"></i> <span class="d-none d-lg-inline-block">General Info</span></a>
</li>
<li class="disabled">
<a class="nav-link" href="#myTickets" data-toggle="tab" role="tab">>MyTickets</span></a>
</li>
...
</ul>
表结构:
registrations table: id, status, congress_id, created_at
congresses table: id, name, created_at,...
ticket type table:id, name, congres_id, created_at, ....
如果您在同一页上有选项卡,那么我相信您不需要分离注册,然后在索引方法中获取并传递它,因为注册是其他选项卡内容的一部分。谢谢,但是用户大会注册只显示在myTickets选项卡中。它将显示在myTickets选项卡中,只需将getRegistrations与index合并,并将注册传递给视图。谢谢,您要说的是将代码放在索引方法内的getRegistrations中?是的,获取
Auth::user
registrations数据并传递给index视图。如果需要获取congres
,则将其作为:compact加载('user','registrations.congres')
The“{$reg}}”只显示注册表“{“id”:1,“congress\u id”:1,“main\u user\u id”:1}”的信息。您知道显示名称、日期等会议信息需要什么吗?您需要另一个循环来解析每次注册的reg,以便在blade中显示信息。但是在索引()中或者在页面中的“我的票”选项卡在哪里?在您的@foreach
中,您需要另一个循环,对于大会
信息,您需要立即加载注册。大会
// Congress model
class Congress extends Model
{
// A conference has many registration types
public function ticketTypes(){
return $this->hasMany('App\TicketType', 'congress_id');
}
public function registrations(){
return $this->hasMany('App\Registration', 'congress_id');
}
}
// RegistrationModel
class Registration extends Model
{
// a registration has one user that do the registration (main_participant_id)
public function customer(){
return $this->belongsTo('App\User');
}
public function congress(){
return $this->belongsTo('App\Congress');
}
}
// TicketTypeModel
class TicketType extends Model
{
public function congress(){
return $this->belongsTo('App\Congress');
}
}
// user model
class User extends Authenticatable
{
// A user can register in many conferences
public function registrations(){
return $this->hasMany('App\Registration','main_user_id');
}
}
registrations table: id, status, congress_id, created_at
congresses table: id, name, created_at,...
ticket type table:id, name, congres_id, created_at, ....
public function index() {
$user = Auth::user();
$registrations = $user->with('registrations.congress');
return view('users.index', compact('user', 'registrations'));
}