It seems like you're encountering an issue where the new accessor syntax introduced in Laravel 9 isn't being recognized when you're passing your model instance to an Inertia response. This could be due to a serialization issue where the accessor methods are not being called when the model is converted to a JSON representation for the Inertia response.
Here's a potential solution to ensure that your accessor is included in the JSON representation:
First, make sure that your accessor method is correctly defined in your Journey model. For example, if you have an accessor for an attribute named example, it should look like this:
use Illuminate\Database\Eloquent\Casts\Attribute;
protected function example(): Attribute
{
return new Attribute(
get: fn ($value) => // Your get logic here,
set: fn ($value) => // Your set logic here, if necessary
);
}
Next, you need to ensure that the accessor is included in the array representation of your model. You can do this by adding the accessor to the $appends property of your model:
protected $appends = ['example'];
This will ensure that when your model is serialized to JSON, the example attribute is included in the JSON representation.
Now, when you pass your model instance to Inertia, the accessor should be included:
Route::get('/{journey}', function (Journey $journey) {
return inertia('Tool', compact('journey'));
});
Make sure that your route model binding is correctly resolving the Journey instance and that the example attribute is accessible on the Journey model instance.
If you're still encountering issues, you may want to manually add the accessor value to the array you're passing to Inertia like so:
Route::get('/{journey}', function (Journey $journey) {
$journeyArray = $journey->toArray();
$journeyArray['example'] = $journey->example; // Manually add the accessor
return inertia('Tool', ['journey' => $journeyArray]);
});
This manually appends the accessor to the array before passing it to Inertia, which can help if automatic serialization isn't including the accessor for some reason.
If none of these solutions work, please ensure that you're using the latest version of Laravel and Inertia, as there may have been bug fixes or updates that address this issue.