My case like this :
My view blade laravel like this :
{!! Form::open(['route' => 'shop.payment']) !!}
<input type="hidden" name="result_type">
<input type="hidden" name="result_data"">
...
<input type="radio" name="payment_method" value="transfer">
....
<checkout-view></checkout-view>
{!! Form::close() !!}
In view blade laravel exist vue component of checkout view
The component like this :
<script>
export default{
template:'<button @click="checkout" class="btn btn-danger pull-right" type="submit">Checkout</button>',
methods: {
checkout(e){
if(window.Laravel.hasOwnProperty('auth')) {
$('#payment-form').attr('action', '/shop/payment/checkout')
return true;
}
else {
$('#payment-form').attr('action', '/shop/detail')
$("#payment-form").attr('method', 'get')
return true
}
}
},
}
</script>
My routes laravel like this :
Route::group(['prefix' => 'shop','as'=>'shop.'], function () {
Route::get('detail', function(){
return view('shop.detail');
});
});
If no auth it will run else
and the url like this :
I want remove the parameter, so the url like this :
I try change to post
I change to be like this :
$('#payment-form').attr('action', '/shop/detail')
$("#payment-form").attr('method', 'post')
return true
And
Route::post('detail', function(){
return view('shop.detail');
});
But it does not work, there exist error :
POST http://myshop.dev/shop/detail 405 (Method Not Allowed)
What is the right solution to solve my problem?
You can do it like this with Input
and get
method:
View
{!! Form::open(['route' => 'shop.payment','method' => 'GET']) !!}
<input type="hidden" name="result_type">
<input type="hidden" name="result_data"">
...
<input type="radio" name="payment_method" value="transfer">
....
<checkout-view></checkout-view>
{!! Form::close() !!}
Route
Route::get('/test/route', 'TestController@yourFunction');
Controller
public function yourFunction(){
$result_type = Input::get('result_type');
$result_data = Input::get('result_date');
......
}
I hope you understand.
Route::group(['prefix' => 'shop','as'=>'shop.'], function () {
Route::get('detail', function(){
return view('shop.detail');
});
});
I believe the route comes out as shopdetail , not shop/detail
Type the command php artisan route:list
to see how laravel sees the urls.
Use return redirect to another route instead of returning a view if there is no auth. In another route on which you are redirecting return the original view which you want to display when there is no authenticated user.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.