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

Nicho's avatar
Level 1

Laravel : Status change not working

Hi, I'm currently developing a web project And trying to implement the finish status to set the status into finish once the booking has been paid. When the finish button is created, the status won't change. How do i resolve this problem??

The Controller :

public function finish($id){
        $booking = Booking::find($id);

        $booking->status = 'Finish';

        $booking->save();

        return redirect()->back();
    }

The Route :

Route::get('/finish/{id}','BookingController@finish');

The blade :

@if($booking->status == 'paid')
            <a href="{{url('finish'), $booking->id}}" class="btn btn-success">
                {{__("Finish")}}
            </a>
        @endif
0 likes
13 replies
tykus's avatar
tykus
Best Answer
Level 104

Don't use a GET request for this.

Route::post('/finish/{id}','BookingController@finish')->name('booking.finish');
@if($booking->status == 'paid')
    <form method="POST" action="{{ route('booking.finish', $booking->id}}">
        @csrf
        <button type="submit" class="btn btn-success">
            {{__("Finish")}}
        </button>
    </form>
@endif
Nicho's avatar
Level 1

@tykus I thought using get was a way. Because i created a testing web for status change to test my logic. It works fine tho

tykus's avatar

@Nicho a GET request should be safe

HTTP methods are considered safe if they do not alter the server state.

Use the form example I shared above instead - this will make a POST request.

Sinnbeck's avatar

So the idea is that any user can just call that endpoint at any time to set their booking as finished (without paying) ?

Anyways. Make sure you are hitting the endpoint

public function finish($id){
       dd($id);
        $booking = Booking::find($id);
Nicho's avatar
Level 1

@Sinnbeck I set it in the blade file, if the booking->status == 'paid', the admin can change the status to finish

Sinnbeck's avatar

@Nicho But anyone can call that route. Or I can trick an admin to click a link that sets mine to paid.

  1. User a put or post request instead of get
  2. Use some sort of authorization to ensure that only an admin can call that url.
Lumethys's avatar

@Nicho what is the different between paid and finished? If it is just an admin check, then you can ditch it altogether

Nicho's avatar
Level 1

@Lumethys So what i want is, that when the customer(the user) is already paid the booking, the customer enjoy the holiday package that they're ordered, after that the vendor(admin) can set the booking status from paid to finish, and send an email to the customer that recently just enjoyed his holiday package and give a review about their experienced

Lumethys's avatar

@Nicho How do your admin know when a booking had finished? I assume there s a time field on the Booking Model?, something like:

Booking{ to:London, start: 10/10/2022, end: 15/10/2020}

if you, cant you just automate the process?

create a schedule, everyday it would check the Booking table:

	$bookings = Booking::where('stattus', 'paid')->get();
	foreach($bookings as $booking){
		$endDate = Carbon::parse($booking->end);
		$now = Carbon::now();

		if ($now->greaterThan($endDate)){			// if today is greater than the booking's last day
			Mail::to($booking->client())->send(new SomeThankYouEMail($booking));

			$booking->status = 'finished'
			$booking->save();

		}
	}
Nicho's avatar
Level 1

@Lumethys How the admin and customer know when their booking is finish, they will recieve an email that tell them the booking is finished

Lumethys's avatar

@Nicho i dont know exactly how you determine when a booking had finished, I assumed it to be an end_date field in your db

The important thing is, there must be someway to programmatically determined whether a Booking is finished

Think about this: If your app grow and there is 1000 client per day, do your admin manually check for thousands of booking per day?

Lumethys's avatar

@Nicho

they will recieve an email that tell them the booking is finished

Who will send this email? the User? Impractical. If your user forgot to mail you, will the status never change? If your app had 5 000 user per day, do your admin need to manually check 5000 box per day?

Automate this process, when someone Book a trip, they must have a start day and an end date, no? "I want to book a trip to Venice from 12/10/2022 to 20/10/2022" or something like that.

Please or to participate in this conversation.