Skip to content

Casting not working with embedded fields #3201

Open
@archit8430

Description

@archit8430
  • Laravel-mongodb Version: 5.1
  • PHP Version: 8.2
  • Laravel Version 11
  • Database Driver & Version:

Description:

How to apply for casting when there is embedded fields

Steps to reproduce

  1. Prepare Create Query
User::create([
    'reg_date' => (new Carbon())->format('Y-m-d'),
    'input_params' => [
      'start_date' => (new Carbon())->format('Y-m-d')
     ],
]);
  1. User
namespace App\Models\MongoDb\IpayApp;

use App\Casts\ObjectIdCasts;
use MongoDB\Laravel\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class User extends Model
{
    use HasFactory;
    protected $connection = 'ipay_app';
    protected $table = 'user';
    protected $guarded = [];

    protected $casts = [
        'reg_date' => 'datetime',
        'start_date' => 'datetime',
    ];

}
  1. reg date is casting properly, while on start casting not work

Expected behaviour

Both Should Cast Accordingly, i have missing something, let me know

Actual behaviour

reg date is casting properly, while on start casting not work

Edited to add code blocks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions