Resource with another name besides "$record".

How can I use another variable name in my EditRecord class, other than "$record"? I get an error when I try to do this in the getPages() method:
'edit' => Pages\EditLocation::route('/{location}/edit'),
'edit' => Pages\EditLocation::route('/{location}/edit'),
I guess it's looking for record specifically. However, I have a class that checks for a "location" route in the request and I need it to specifically check this. OR I need it to be able to see if {record} is an instance of Location, but it seems that {record} is just a string or an Int, so I don't think that's possible. If anyone knows a way around this, that would be helpful.
5 Replies
Dennis Koch
Dennis Koch5mo ago
I don't think you can change that, because it's looking for $record in the mount method of the Livewire components
Jon Mason
Jon Mason5mo ago
that's unfortunate...maybe it's not doable, but it would be great it if also accepted a Model instance instead of just a string|int.
Dennis Koch
Dennis Koch5mo ago
What do you mean? $record is a model instance
Jon Mason
Jon Mason5mo ago
hmm...I thought I remembered the mount method accepting a string or an int. My situation is that I have the concept of "locations" in my app, where a user can select a location and then functionality related to that specific location becomes available. so my route would be like team/2/location/1009/edit. I have a "CheckSession" middleware, where I make sure that nothing goes wrong, like the location isn't stored in the session, or something like that:
$selectedLocation = $request->route('location');

//if the url doesn't match what's in the session, or the session is empty, then sync it up.
if (!empty($selectedLocation) && !($selectedLocation instanceof Location)) {
}
$selectedLocation = $request->route('location');

//if the url doesn't match what's in the session, or the session is empty, then sync it up.
if (!empty($selectedLocation) && !($selectedLocation instanceof Location)) {
}
If the route was named "location", or "1009" was an instance of Location then I could do the above check if it's an instance of Location. But doing $request->route('record'), could be anything.. I think I'll just have to check within my LocationResource, but I was hoping to be able to just check this universally within the middleware.
awcodes
awcodes5mo ago
$record is inferred so you should still be able to check its instanceof
Want results from more Discord servers?
Add your server
More Posts