Yahav
108
3
Laravel

Route-Model binding doesn't work

Posted 1 month ago by Yahav

Hey guys

I have this really odd problem in which the the route-model binding doesn't seem to work while if i remove the model type hint from the controller and do find($id) instead it works like a charm. The Route: Route::get('stream/{channelStream}/edit', '[email protected]')->name('stream.edit'); The Model: class ChannelStream extends Model The DB Table name: channel_streams The controller method: public function edit(ChannelStream $stream)

However, i don't get 404, and a query isn't logged for this request.. When i dump $stream inside the controller i get the following:

debug
ChannelStream {#881 ▼
  #fillable: array:4 [▶]
  #hidden: []
  #with: []
  +sortable: array:2 [▶]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: []
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #visible: []
  #guarded: array:1 [▶]
}

Basically, its empty, it doesn't fetch the db record.

Any ideas what can this be?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.