I have a list of hotels in a select I want update the database base on the hotel selected if it update the field I want to alert it on the home page. this is the ajax function
function showRoom($hotel_plan_id) {
var id = $hotel_plan_id;
if (id !== "") {
$.ajax({
type: "POST",
dataType: 'JSON',
url:'/'+id,
data:{_token:''},
success:function(data){
alert(data);
},
error: function (result) {
alert("Error occur in the update()");
}
});
}
} my controller
public function update(Request $request, $hotel_plan_id)
{
$hotel=plan_hotel::where('hotel_plan_id', $hotel_plan_id)->first();
$hotel->hotel_name = $request->input('hotel_name');
//$hotel ->room_name = $request->input('room_name');
$hotel->save();
return redirect('/home')->with('success', 'price updated');
}
my route
Route::post('home/{hotel_plan_id}', 'HomeController@update')->name('home');
my select form
{!! Form::select('hotel_name', array($item[4], $item[10]),'S', array('style'=>' Border:none; ', 'id' => 'hotel_id', 'onclick'=>"showRoom(this.value, $item[8])"));!!}
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OZdkoT
via IFTTT
Aucun commentaire:
Enregistrer un commentaire