Postingan lainnya
Kelas Premium!
Belajar Javascript untuk website
Gunakan kupon "mulaijs" untuk diskon 75 ribu!
Modal laravel dengan ajax
Button
<label>Request</label>
<button class="btn btn-outline-primary col-md-12" data-toggle="modal"
data-target="#modalRequest" id="addRequest">Request</button>
<div class="invalid-feedback">
Input Request !
</div>
</div>
Modal
<div class="modal-body">
<p>Tambahkan Request disini</p>
<div class="form-group">
<textarea id="notes"></textarea>
</div>
</div>
<div class="modal-footer bg-whitesmoke br">
<button type="button" class="btn btn-outline-danger" data-dismiss="modal">Cancel</button>
<button type="button" onclick="sendRequest()" class="btn btn-outline-primary">Save changes</button>
Ajax
function sendRequest() {
var requestes = tinyMCE.get('notes').getContent();
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
}),
$.ajax({
url: '{{ route('editRequest', ['id' => request()->route('id')]) }}',
method: "post",
dataType: 'JSON',
data: {
request: requestes,
},
success: function (respons) {
$('#lihatRequest').empty();
$('#lihatRequest').append(requestes);
if (respons.ping == 200) {
iziToast.success({
title: 'Berhasil!',
message: 'berhasil memasukkan Request',
position: 'bottomRight'
});
$('#modalRequest').modal('hide');
} else {
iziToast.info({
title: 'gagal!',
message: 'gagal memasukkan Request',
position: 'bottomRight'
});
}
}
})
}
web.php
Route::post('{id}/edit-request', 'OrderController@editRequest')->name('editRequest');
Route::get('{id}/view-request', 'OrderController@viewRequest')->name('viewRequest');
Controller
public function editRequest(Request $request, $id) {
$user = $request->user();
$order = Orders::where('order_id', $id)->first();
$insertRequest = Orders::where('order_id', $id)->update(['request' => $request->input('request')]);
if($insertRequest) {
$users = User::all();
Notification::send($users, new addedRequest($user, $order));
$response['ping'] = 200;
} else {
$response['ping'] = 500;
}
return json_encode($response);
}
public function viewRequest($id) {
$viewRequest = Orders::where('order_id', $id)->get();
return response()->json($viewRequest);
}
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban