如何将数据从一个页面正确传递到另一个页面(laravel)

时间:2018-03-24 01:36:16

标签: php laravel

我有一个会议详细信息页面和一个在会议中注册的页面。在会议详细信息页面中,用户从会议的每种注册类型中选择需要多少注册,然后单击按钮"下一步"去登记页面。我怀疑如何将数据从会议详细信息页面传递到注册页面?因为在注册页面中需要显示用户在会议详细信息页面中选择的注册数量的摘要。

我的结构是:

我有一个FrontEndController,它有一个show方法来显示会议详细信息页面:

public function show($id, $slug){
        $conf = Conference::where('id', $id)->first();
        $registrationTypes = RegistrationType::where('conf_id', $conf->id)->get();
        return view('confs.show')->with('conf',$conf)->with('registration_types', $registrationTypes);
    }

上述方法的路线:

Route::get('/conference/{id}/{slug?}', [
    'uses' => 'FrontEndController@show',
    'as'   =>'confeerences.show'
]);

在会议详情页面中,当用户访问" http://proj.test/conference/1/test-conference"用户可以选择想要获取的注册数量。例如,如果会议有2种注册类型(rt01和rt02),则用户可以选择他想要2种注册类型" rt01"和2个来自注册类型" rt02"的注册。为此,下面的代码在会议详细信息视图中有选择菜单,允许用户选择每种注册类型的数量:

<div class="card">
    <div class="card-header d-flex justify-content-between">
        <span>Registration</span>
        <span>Quantity</span>
        <span>Price</span>
    </div>
    <div class="card_body">
        <ul class="list-group list-group-flush">
            @foreach($registration_types as $rtype)
                <li class="list-group-item d-flex align-items-center justify-content-between">
                    <div class="w-100 text-truncate">
                        <span>{{$rtype->name}}</span>
                    </div>
                    <form>
                        <select class="custom-select form-control rtype_name"
                                 id="rtype_{{ $rtype->id }}" data-price="{{ $rtype->price }}" name={{ $rtype->name }}>
                            <option selected></option>
                        @for ($i = $rtype->min_participants; $i <= $rtype-> max_participants; $i++)
                                <option value="{{ $i }}">{{ $i }}</option>
                            @endfor
                        </select>
                </form>
                <span class="font-size-sm w-50 text-right">X {{$rtype->price}}€</span>
                </li>
            @endforeach
            <li class="list-group-item d-flex align-items-center justify-content-between">
                <div>
                    <span>TOTAL</span>
                </div>
                <span class="total">0.00€</span>
            </li>
        </ul>
    </div>
    <div class="card-footer">
        <a  href="{{route('conferences.registration', ['id' => $conf->id, 'slug' => $conf->slug])}}">Next</a>
    </div>
</div>

用户选择他想要的每种注册类型的注册数量后,可以点击下一步进入注册页面。

所以我创建了这条路线:

Route::get('/conference/{id}/{slug?}/registration', [
    'uses' => 'FrontEndController@registration',
    'as'   =>'conferences.registration'
]);

在FrontEndController中我有方法:

public function registration(){
        return view('conferences.registration');
    }

然后他进入了一个注册页面,在这个页面中显示如下摘要是必要的:

registration_types       quantity             price          subtotal
rt01                        2                   5.00$           10.00$    
rt02                        1                   10.00$          10.00$                 
TOTAL                                                           20.00$

我现在在registration.blade.php文件中有这个静态:

 <div class="card">
    <div class="card-header d-flex justify-content-between">
        <span>Summary</span>
    </div>
    <div class="card_body">
        <ul class="list-group list-group-flush">
            <li class="list-group-item list-group-registration d-flex align-items-center justify-content-between">
                <span>Registration Type</span>
                <span>Quantity</span>
                <span>Price</span>
                <span>Subtotal</span>
            </li>
            <li class="list-group-item list-group-registration d-flex align-items-center justify-content-between">
                <span>rt01</span>
                <span>2</span>
                <span>5.00$</span>
                <span>10.00$</span>
            </li>
            <li class="list-group-item list-group-registration d-flex align-items-center justify-content-between">
                <span>rt02</span>
                <span>1</span>
                <span>10.00$</span>
                <span>10.00$</span>
            </li>
            <li class="list-group-item list-group-registration d-flex align-items-center justify-content-between">
                <span>TOTAL</span>
                <span>20.00€</span>
            </li>
        </ul>
    </div>
</div>

的疑问:

我的疑问是如何将必要的信息从会议详细信息视图传递到注册视图,因此可以显示上面的摘要但是可以显示动态数据。也许我可以在FrontEndController中使用类似的东西:

public function registration($id, $slug){
        $conf = Conference::where('id', $id)->first();
        $registrationTypes = RegistrationType::where('conf_id', $conf->id)->get();
        return view('confs.show')->with('conf',$conf)->with('registration_types', $registrationTypes);
        return view('confs.registration')->with('conf',$conf)->with('registration_types', $registrationTypes);

    }

但是我已经为会议详细信息页面做了这个,是不是可以将会议详细信息页面中的信息传递到注册视图而无需再次查询数据库?并且使用上述方法,所选数量也无法传递到注册视图,因为它们不在数据库中。您知道怎样才能将数据从会议详细信息视图正确传递到注册视图吗?

0 个答案:

没有答案