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

Mrxqwe's avatar

Update Method not working, no access to variables

Hi,

sorry for such a stupid question but I can't find the root cause. Maybe you can give me a hint.

I have created a laravel app for a bus reservation with normal CRUDs. I think the issue is related to route model binding of $booking is not working correctly, not getting the Object details for id 116 .... but more details below. If you need more, please ask.

Here the web.php

// Busbookings
Route::delete('busbookings/massdestroy', 'BusBookingController@massDestroy')->name('busbookings.massDestroy');
Route::delete('busbookings/destroy', 'BusBookingController@massDestroy')->name('busbookings.destroy');
Route::get('busbookings', 'BusBookingController@index')->name('busbookings.index');
Route::get('busbookings/{booking}', 'BusBookingController@show')->name('busbookings.show');
Route::get('busbookings/{booking}/edit', 'BusBookingController@edit')->name('busbookings.edit');
Route::put('busbookings', [BusBookingController::class, 'update'])->name('busbookings.update');

Blade views of index and show are working as expected. But when I press OK in edit.blade.php access to the parameters is not working.

edit.blade.php

@extends('layouts.admin')
@section('content')

<div class="card">
    <div class="card-header">
        {{ trans('global.edit') }} {{ trans('cruds.busbooking.title_singular') }}
    </div>

    <div class="card-body">
        <form method="POST" action="{{ route("admin.busbookings.update", [$booking->id]) }}" enctype="multipart/form-data">
            @method('PUT')
            @csrf
[...]
<div class="form-group">
                <button class="btn btn-danger" type="submit">
                    {{ trans('global.save') }}
                </button>
            </div>
        </form>
    </div>
</div>

@endsection

BusController.php

 public function update(UpdateBusBookingRequest $request, BusBooking $booking)
    {
        //dd($request);
        //dd($booking);
        //dd($request->query() );
        
        $booking->update($request->all());

        return redirect()->route('admin.busbookings.index')->with('success','Buchung erfolgreich verarbeitet.');;
    }

Debug from dd($request)

App\Http\Requests\UpdateBusBookingRequest {#2297 ▼
  #container: Illuminate\Foundation\Application {#2 ▶}
  #redirector: Illuminate\Routing\Redirector {#2299 ▶}
  #redirect: null
  #redirectRoute: null
  #redirectAction: null
  #errorBag: "default"
  #stopOnFirstFailure: false
  #validator: Illuminate\Validation\Validator {#2057 ▶}
  #json: Symfony\Component\HttpFoundation\ParameterBag {#2053 ▶}
  #convertedFiles: []
  #userResolver: Closure($guard = null) {#1764 ▶}
  #routeResolver: Closure() {#1775 ▶}
  +attributes: Symfony\Component\HttpFoundation\ParameterBag {#2295 ▼
    #parameters: []
  }
  +request: Symfony\Component\HttpFoundation\InputBag {#2045 ▼
    #parameters: array:11 [▼
      "_method" => "PUT"
      "_token" => "GYQvMg0vqrwEGcFUyoJJ79zYPweBOHw1d1w9tMUc"
      "asset_id" => "5"
      "tenant_id" => "6"
      "start_date" => "26.08.2022"
      "start_time" => "18:15"
      "end_date" => "27.08.2022"
      "end_time" => "18:15"
      "km" => "0"
      "total_amount" => "0"
      "status_id" => "10"
    ]
  }
  +query: Symfony\Component\HttpFoundation\InputBag {#2047 ▼
    #parameters: array:1 [▼
      116 => null
    ]
  }
  +server: Symfony\Component\HttpFoundation\ServerBag {#2051 ▶}
  +files: Symfony\Component\HttpFoundation\FileBag {#2293 ▶}
  +cookies: Symfony\Component\HttpFoundation\InputBag {#2049 ▶}
  +headers: Symfony\Component\HttpFoundation\HeaderBag {#2291 ▶}
  #content: ""
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: null
  #requestUri: null
  #baseUrl: null
  #basePath: null
  #method: null
  #format: null
  #session: Illuminate\Session\Store {#1832 ▶}
  #locale: null
  #defaultLocale: "en"
  -preferredFormat: null
  -isHostValid: true
  -isForwardedValid: true
  -isSafeContentPreferred: null
  pathInfo: "/admin/busbookings"
  requestUri: "/admin/busbookings?116"
  baseUrl: ""
  basePath: ""
  method: "PUT"
  format: "html"
}

Debug from dd($booking)

App\Models\BusBooking {#2061 ▼
  +table: "bookings"
  #dates: array:5 [▼
    0 => "start_date"
    1 => "end_date"
    2 => "created_at"
    3 => "updated_at"
    4 => "deleted_at"
  ]
  #fillable: array:17 [▼
    0 => "asset_id"
    1 => "tenant_id"
    2 => "start_date"
    3 => "start_time"
    4 => "end_date"
    5 => "end_time"
    6 => "status_id"
    7 => "created_at"
    8 => "updated_at"
    9 => "deleted_at"
    10 => "title"
    11 => "orga_id"
    12 => "total_amount"
    13 => "km"
    14 => "discount"
    15 => "haushaltsstelle"
    16 => "agb"
  ]
  #connection: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  +preventsLazyLoading: false
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #escapeWhenCastingToString: false
  #attributes: []
  #original: []
  #changes: []
  #casts: array:1 [▼
    "deleted_at" => "datetime"
  ]
  #classCastCache: []
  #attributeCastCache: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
  #forceDeleting: false
}

Debug output from $request->query(); looks like this

array:1 [▼
  116 => null
]

I think this is the issue ...

  +query: Symfony\Component\HttpFoundation\InputBag {#2047 ▼
    #parameters: array:1 [▼
      116 => null

Why is it not working with the object binding to busbooking?

BR

0 likes
7 replies
Sinnbeck's avatar

You never bind the booking in the update route

Route::put('busbookings/{booking}', [BusBookingController::class, 'update'])->name('busbookings.update');
Mrxqwe's avatar

@Sinnbeck Tried this as well but received then

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The PUT method is not supported for this route. Supported methods: GET, HEAD.
http://localhost:8000/admin/busbookings?116=
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Mrxqwe Check what url it renders

And try this

<form method="POST" action="{{ route("admin.busbookings.update", $booking->id) }}" enctype="multipart/form-data">
1 like
Mrxqwe's avatar

@Sinnbeck BINGO !!! Many thanks !!! Without [] is it working as expected now.

Thanks !

Sinnbeck's avatar

Also pick one way of definining controllers and stick to it

'BusBookingController@massDestroy'
//or
[BusBookingController::class, 'massDestroy']
Mrxqwe's avatar

@Sinnbeck Thanks for your quick reply. Left overs as I tried the other way using the syntax.

Please or to participate in this conversation.