To bypass the accessor and retrieve the raw value of the date attribute, you can use the getAttributeValue method provided by Eloquent. Here's an example of how you can modify your code to achieve this:
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Carbon\Carbon;
class Shift extends Model
{
use HasFactory, HasUuids;
public $guarded = [];
protected function date(): Attribute
{
return Attribute::make(
get: fn ($value) => Carbon::parse($value)->format('l, jS F '),
);
}
public function getRawDateAttribute()
{
return $this->getAttributeValue('date');
}
}
In this solution, we added a new method called getRawDateAttribute to the Shift model. This method uses the getAttributeValue method to retrieve the raw value of the date attribute, bypassing the accessor.
Now, you can access the raw date value by calling $model->raw_date on an instance of the Shift model.