首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从$registration获得注册信息?(雄辩)

如何从$registration获得注册信息?(雄辩)
EN

Stack Overflow用户
提问于 2018-06-07 16:14:25
回答 1查看 63关注 0票数 0

用户可以访问一个页面,在其中显示一个列表,并在会议中进行下一次注册,也就是说,在尚未发生的会议中进行注册。对于用户所做的每一项登记,如果该登记尚未支付,即登记表中该登记的状态栏为"I“(不完全),则显示”支付“链接:

代码语言:javascript
复制
@foreach($nextRegistrations as $nextRegistration)
    @if(!empty($nextRegistration->conference || !empty($nextRegistration->conference->start_date)))
        <li class="list-group-item">
            <h5>{{optional($nextRegistration->conference)->name}}</h5>
             @if ($nextRegistration->status === 'I')
                    <a href="{{route('conferences.showPaymentPage',
                        ['id' => $nextRegistration->conference->id,
                        'slug' => $nextRegistration->conference->slug,
                        'regID'=> $nextRegistration->id])}}"
                        class="btn btn-primary ml-2"> Pay  
                    </a>
            @endif
        </li>
    @endif
@endforeach 

当用户单击“支付”时,应该将其重定向到"http://proj.test/conference/2/conference-title/payment/registration/6“这样的支付页面,其中6是用户要支付的注册id,"2”是会议id,因此用户使用id "2“支付有关会议的注册。

在注册付款页面中应出现注册摘要。例如,如果用户在具有3种票证/注册类型、1种类型为"general“和2种类型为"plus”的会议上进行了注册,则应该出现一个摘要,如下所示:

代码语言:javascript
复制
Title of the conference (ex: Conference test)
Date of the conference

Registration Type   Quantity         Price     Subtotal
 general             1            0.00 €      0.00$
 plus                2            1.00 €      2.00$

因此,当用户单击“支付”按钮时,我有此路由:

代码语言:javascript
复制
Route::get('/conference/{id}/{slug?}/payment/registration/{regID}', [
    'uses' => 'PaymentController@showPaymentPage',
    'as'   =>'conferences.showPaymentPage'
]);

showPaymentPage()中,我得到了PaymentController的注册,我得到了用户想用“$registration = Registration::find($regID);”支付的注册:

代码语言:javascript
复制
class PaymentController extends Controller
{
   public function showPaymentPage($id = "", $slug = "", $regID){
      $registration = Registration::find($regID);

//dd($registration->conference) shows Conference {#282 ▼ #fillable: array:18 [▶]...}
//dd($registration->customer) shows User {#282 ▼ #fillable: array:13 [▶]...}

    }
}

怀疑:

您知道如何从$registration获得必要的信息来显示注册信息,如上面的摘要所示?

问题的相关表结构:

代码语言:javascript
复制
Registration table:

    id, status, conference_id, main_participant_id

Registration Types table:

    id, name, price, confernece_id

Conference table:

    id, name, date, organizer_id

Participant table:

id, registration_id, registration_type_id, name, surname

问题的相关模型:

用户模型:

代码语言:javascript
复制
 class User extends Authenticatable
    {
        public function conferences(){
            return $this->hasMany('App\Conference', 'organizer_id');
        }
        public function registrations(){
            return $this->hasMany('App\Registration','main_participant_id');
        }
    }

会议模式:

代码语言:javascript
复制
class Conference extends Model
{
    public function organizer(){
        return $this->belongsTo('App\User', 'organizer_id');
    }
    public function registrationTypes(){
        return $this->hasMany('App\RegistrationType', 'conference_id');
    }
    public function registrations(){
        return $this->hasMany('App\Registration', 'conference_id');
    }
}

登记类型模型:

代码语言:javascript
复制
class RegistrationType extends Model
{
    public function conference(){
        return $this->belongsTo('App\Conference');
    }

    // a registration can have many participants
    public function participants(){
       return $this->hasMany('App\Participant');
    }
}

登记模式:

代码语言:javascript
复制
class Registration extends Model
{
    // a registration has one user that do the registration
    public function customer(){
        return $this->belongsTo(User::class, 'main_participant_id', 'id');
    }

    // a registration can have many participants
    public function participants(){
       return $this->hasMany('App\Participant');
    }

    public function conference(){
        return $this->belongsTo('App\Conference');
    }

    public function payment()
    {
        return $this->hasOne('App\Payment');
    }
}

参与者模型:

代码语言:javascript
复制
class Participant extends Model
{

    // a participant belongs to a registration
    public function registration(){
        return $this->belongsTo('App\Registration');
    }

    public function registration_type(){
        return $this->belongsTo('App\RegistrationType');
    }
}
EN

回答 1

Stack Overflow用户

发布于 2018-06-07 16:38:28

我认为您的模式有点奇怪。从URI的外观看,您似乎在请求有关特定“注册”的信息,但您正在显示所有用户的注册。为了清晰起见,您应该使用类似于http://proj.test/conference/{conference_id}/registration/status的东西。

您的问题是缺少registration_type_id列ub registration表。无法将用户与注册类型连接起来。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50745886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档