Laravel changing route links based on database records

Viewed 46

I'm building an application that schedules aircraft for flight schools/flying clubs, etc.

I currently have a schedule grid running that allows the user to click on a square to book a reservations starting at that time. That function works perfectly, however, if a single booking exists in the system, for some reason, Laravel deletes the final part of the URL, throwing a 404. Any thoughts on this? I inspected the page and it physically looks like the view is being altered, although the code clearly shows this part. See below:

When there are no records, if a user selects a box on the grid, they are directed to finalize the booking at: /app/schedule/new/{time}/{date}/{resource}/{instructor?}

For example, a booking starting at 730am today with no instructor using resource #1 (plane 1) is: /app/schedule/new/0730/20201204/1

However, when there is a booking in the system, all boxes on the grid point to /app/schedule/new/{time}/{date}

Or, in our example: /app/schedule/new/0730/20201204 (this is incorrect, there should be a /1 at the end)

Here is my route:

Route::get('/app/schedule/new/{time}/{date}/{resource}/{instructor?}', 'ScheduleController@show_new_booking_form');

And the view href which points to the correct link (instructor is optional):

<a href="/app/schedule/new/0730/{{$raw_date}}/{{$aircraft->aircraft_id}}">

(Edited) Complete steps for all this to happen.

  1. User visits the bookings page with the schedule grid. This is where they would select the link from above. The controller method for that is:
public function show_schedule(Request $request)
    {
        // Reference Variables
        $days = $request->days;
        $org_id = Auth::user()->org;

        // Information on Dates & Date Incremation
        $today = Carbon::now('US/Eastern');
        $date = $today->addDays($days);
        $schedule_date = $date->isoFormat('dddd MMMM D, YYYY');
        $raw_date = $date->isoFormat('YYYYMMDD');
        
        $aircraft = DB::table('aircraft')->where('org', $org_id)->get(); // gets all aircraft for this organization
        $bookings = DB::table('bookings')->where('org', $org_id)->get();

        // Grid date info
        $grid_date = $date->isoFormat('YYYY-MM-DD');

        return view('schedule/schedule')->with(compact('raw_date','schedule_date', 'days', 'aircraft','bookings','grid_date'));
    }

Then, they are presented with a form where they finish the booking if they are rerouted correctly. The view for the main schedule grid consists of a foreach loop to break the collection of aircraft into individual records:

@foreach ($aircraft as $aircraft)
          <tr>
            <th scope="row" data-toggle="tooltip" data-placement="right" title="{{$aircraft->type}}">{{ $aircraft->aircraft_n }}</th>
            <td class="sh-td"><a href="/app/schedule/new/0700/{{$raw_date}}/{{$aircraft->aircraft_id}}"><div class="td-clickable"></div></a></td>

... this continues for all times until 830pm (each gets it's own td)

0 Answers
Related