Laravel Pivot table extra date-time field format (Not timestamp) using carbon object
The best solution I would suggest is creating custom pivot model for this relation:
// Offer model (the same goes for the User model, but change to 'instanceof Offer`
public function newPivot(Eloquent $parent, array $attributes, $table, $exists)
{
if ($parent instanceof User) return new OfferUserPivot($parent, $attributes, $table, $exists);
return parent::newPivot($parent, $attributes, $table, $exists);
}
// OfferUserPivot
use Illuminate\Database\Eloquent\Relations\Pivot;
class OfferUserPivot extends Pivot {
// override either property:
protected $dates = ['use_time'];
// or method:
// public function getDates()
// {
// return ['use_time']; // and other columns like created_at etc if you like
// }
}
// Then you can do this:
$user->offers->first()->pivot->useTime; // Carbon object
$offer->users->first()->pivot->useTime; // Carbon object