@smitsanghvi94 Make sure your model allows cartonsData to be fillable.
e.g. In your InwardTransaction model
protected $fillable = ['date', 'type', 'description', 'cartonsData'];
And I assume it's not a custom attribute!
I'm trying to pass an attribute (cartonsData) into my InwardTransaction model, process it inside the model, and save related details in another model (CartonTransaction). However, I noticed that cartonsData is blank before it reaches my model's saving event.
My Tinker Test
$transaction = InwardTransaction::create([
'date' => '10/03/2025',
'type' => \App\Enums\TransactionType::INWARDS,
'description' => 'Random',
'cartonsData' => [
[
"items" => [
["item_id" => "1", "quantity" => "100"],
["item_id" => "2", "quantity" => "100"]
],
"numCartons" => "1"
],
[
"items" => [
["item_id" => "3", "quantity" => "1000"]
],
"numCartons" => "5"
]
],
]);
echo($transaction);
Issue When I log the data inside the booted() method of my model, the cartonsData attribute is empty.
protected static function booted(): void
{
static::saving(function (self $transaction) {
Log::info("Data Received:", $transaction->toArray());
});
}
Log I received:
[2025-03-24 12:07:32] local.INFO: Data Received: {"date":"2025-10-03T00:00:00.000000Z","type":"inwards","description":"Random"}
What I Need
-I want to properly retrieve the cartonsData attribute in the model.
-Process it inside the model.
-Save the details into a related model CartonTransaction (which belongs to InwardTransaction).
What Could Be Wrong?
-Is Laravel stripping out cartonsData before it reaches the model?
-Do I need a mutator (setCartonsDataAttribute) to ensure it persists?
-Is fillable or casts affecting this behavior?
Any insights would be appreciated! Thanks.
Please or to participate in this conversation.