Ajax update field database field in laravel blade template

Related searches

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:'{{ route('home', '') }}/'+id,
    data:{_token:'{{ csrf_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])"));!!}

You have error with ajax url and you dont also pass the value of hotel name.

Check this changes.

function showRoom($hotel_plan_id) {
var id = $hotel_plan_id;
if (id !== "") {
  $.ajax({
    type: "POST",
    dataType: 'JSON',
    url:'/home/' + id,
   data:{_token:'{{ csrf_token() }}', hotel_name: 'Your value here'},
  });
}

Ajax update field database field in laravel blade template, Ajax update field database field in laravel blade template. I have a list of hotels in a select I want update the database base on the hotel� I'm really new on implementing Ajax in Laravel Blades. I've been searching for tutorials and such but it's really confusing. I hope you'll be patient with me. So I have a blade that I want to apply Ajax with so it will refresh like maybe every second. I wonder if it's advisable to apply Ajax on the whole page itself.

Please return json response

return response()->json();

Ajax update field database field in laravel blade template – Laravel , 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. Update data from database using Laravel framework Previous Next In this example we will discuss about how to update a record or data from MySQL database using laravel framework PHP.

You have to return json object like this

return response->json([
       'status'    =>  200,
       'result'    => true,
       'error'     => false,
       'data'      => $hotel
 ]);

Update data from database using Laravel and Ajax, Update data from database using Laravel and Ajax - Learn Update data from database using Laravel edit.blade.php class="form-group"> <strong>Name:< /strong> <input type="text" id="name" name="name" value="{{ layout.blade.php . In this installment, we'll examine a cool Laravel AJAX CRUD Tutorial. There are a few benefits to handling database interactions with ajax. We know that it helps to make page updates very quick, reduces the amount of bandwidth used, and provides for a slick user experience.

Update data from database using Laravel framework, In this example we will discuss about how to update a record or data from MySQL database stud_edit_view.blade.php (resources/views/stud_edit_view.blade. php) <form action = "/edit/<?php echo $users[0]->id; ?> Laravel Update AJAX. Laravel DataTable Crud with Ajax and Model. Follow the following steps and create your laravel datatable ajax crud application with bootstrap modal: Step 1: Install Fresh laravel Setup; Step 2: Set database Credentials; Step 3: Create Migration And Model; Step 4: Install Yajra DataTables in App; Step 5: Create Route, Controller & Blade View

Insert Update and Delete record with AJAX in Laravel, Insert Update and Delete record with AJAX in Laravel Table structure; Database Configuration; Model; Controller; Route; View I am using users table in the example. if($value){ echo $value; }else{ echo 0; } }else{ echo 'Fill all fields. Create a new index.blade.php file in resources/views/ directory. Blade is the simple, yet powerful templating engine provided with Laravel. Unlike other popular PHP templating engines, Blade does not restrict you from using plain PHP code in your views. In fact, all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application.

Laravel 5.8 DataTables Ajax Crud Tutorial – Today we will discuss how to create crud operation using the dataTable. We are going to show you how to create users list, create users, edit users and delete users with dataTable.

Comments
  • alert(id) what r u getting?
  • It is still not updating I changed the url.
  • I checked my value actually the value is empty is empty
  • because I used onclick because when you click you are not directly clicking to dropdown
  • this is the alert I put on my ajax to be returned when there is error alert("Error occur in the update()");
  • It is still not updating.