Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nae's avatar
Level 1

Change status in table

Hi. How change status from 1 to 0 in table seats when i do reservation and choose a seat from this table and insert in table booking?

All the seats is in a separate table. I call this seats with ajax when choose the date for trip. All the seats show depend what date i choose.

public function bookingForm ( Request $request){

//dd($request);

$request->validate([

'addperson.*.name' => 'required',
'addperson.*.phone' => 'required',
'addperson.*.email' => 'required',
'addperson.*.date' => 'required',
'addperson.*.stationroute' => 'required',
'addperson.*.pricestation' => 'required',

],[

'addperson.*.name.required' => 'Introduceți Numele și Prenumele.',
'addperson.*.phone.required' => 'Introduceți Telefonul Mobile.',
'addperson.*.email.required' => 'Introduceți Email.',
'addperson.*.date.required' => 'Alegeți data și ora.',
'addperson.*.stationroute.required' => 'Alegeți destinația.',
'addperson.*.pricestation.required' => 'Alegeți prețul conform vîrstei dumneavoastre.',

]);

foreach ($request->addperson as $key => $value) { BookingNow::create([ 'route_id' => $value['route_id'], 'user_id'=> $user_id = auth()->user()->id, 'name' => $value['name'], 'description' => $value['description'],

  'seat_no' => $value['seat_no'],

  'phone' => $value['phone'],
  'email' => $value['email'],

  'date' => $value['date'],
  'hour' => $value['hour'],
  'stationroute' => $value['stationroute'],
  'pricestation' => $value['pricestation'],
 
]);

}

    Session::flash('success','Rezervarea a fost adaugat cu success');
    return redirect()->back();
}
0 likes
4 replies
Nakov's avatar

@nae You will get a better answer if you share some code.

So I will expect that you have the seat already selected and you are trying to assign it to a booking. So at the same time while you are assigning the booking, you can also update the seat status.

nae's avatar
Level 1

thanks, this i understand, but i don't now how to this))

Nakov's avatar

I don't understand your code a lot. But do you have a Seat model, do you have a table called seats? Where do you track it's status?

if this $value['seat_no'], is a seat id from your database then just get the instance of it:

$seat = Seat::where('seat_no', $value['seat_no'])->first();
$seat->update(['status' => false]); // false = 0

Something like this.

nae's avatar
Level 1

Thanks, sorry i add the code from controller, in view i call the seat with ajax.First i choose the date for trip and after this show all the seats for this date. Thanks for help

Please or to participate in this conversation.