I updated to 3.30 Nova and noticed my implementation of a BelongsToMany is not properly displaying the date values in the index or edit mode. Hoping someone can point me in the right direction -- tried methods in the internet to resolve it.
Test Model File:
protected $dates = [
'created_at',
'updated_at',
'due_date'
// 'test_user.invited_date' => 'datetime'
];
protected $casts = ['other_question_types' => 'boolean',
'due_date' => 'date',
// 'test_user.invited_date' => 'date:Y-m-d'
];
public function user()
{
return $this->belongsToMany(User::class,'test_user')->using(TestUser::class);
}
User Model File:
protected $casts = [
'email_verified_at' => 'datetime',
// 'test_user.invited_date' => 'date:Y-m-d'
];
public function tests()
{
return $this->belongsToMany(Test::class,'test_user')->withPivot(['invited_date']);
}
Test NOVA Resource:
public function fields(Request $request)
{
return [
ID::make(__('ID'), 'id')->sortable(),
BelongsToMany::make('User')->fields(new TestUserFields()),
BelongsTo::make('Category')->rules('required')->withoutTrashed(),
Text::make('Name'),
Text::make('Description')->hideFromIndex(),
Date::make('Due Date','due_date')->sortable(),
Boolean::make('Other Question Types'),
];
}
User Nova Resource:
BelongsToMany::make('Tests')->fields(new TestUserFields())
TestUsersFields Class:
public function __invoke()
{
return [
Date::make('Invited Date')->displayUsing(function(){
return isset($this->pivot) ? \Carbon\Carbon::parse($this->pivot->invited_date)->format('M d, Y') : NULL;
}),
Date::make('Completed Date')->displayUsing(function(){
return isset($this->pivot) ? \Carbon\Carbon::parse($this->pivot->completed_date)->format('M d, Y'): NULL;
}),
];
}