I'm developing a simple ticket purchasing app using Laravel.
I'm having trouble to update the view after the users have selected the tickets to purchase where doesn't matter whether what type of redirect I used in ajaxRequestPost, the view still stuck at / instead of redirect to payments/{id}.
However, I did get a return of the file payments.index but the view did not update to the returned content.
routes/web.php
Route::resource('/', 'TicketController');
Route::post('createOrder', 'OrderController@ajaxRequestPost');
Route::get('/payments/{id}', 'PaymentController@show');
TicketController.php
public function index(){
$tickets = Ticket::all();
return view('tickets.index', compact('tickets'));
}
OrderController.php
public function ajaxRequestPost(Request $request)
{
$input = $request->all();
for($i = 1; $i < 4; $i++){
if($input['ticket_'.$i.'_q'] != 0) {
$spkAdmin = new Order();
$spkAdmin->ticket_id = $i;
$spkAdmin->quantity = (int)$input['ticket_'.$i.'_q'];
$spkAdmin->total = (int)$input['ticket_'.$i.'_t'];
$spkAdmin->user_id = $input['user_id'];
$spkAdmin->save();
$orders = array(
'id' => $i,
'quantity' => (int)$input['ticket_'.$i.'_q'],
'total' => (int)$input['ticket_'.$i.'_t']
);
}
}
return redirect()->action(
'PaymentController@show', ['id' => $input['user_id']]
);
}
PaymentController.php
public function show($id)
{
$orders = DB::table('orders')->where('user_id', $id)->get();
return view('payments.index', ['orders' => $orders]);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire