Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting not working with embedded fields #3201

Open
archit8430 opened this issue Nov 8, 2024 · 1 comment
Open

Casting not working with embedded fields #3201

archit8430 opened this issue Nov 8, 2024 · 1 comment

Comments

@archit8430
Copy link

archit8430 commented Nov 8, 2024

  • 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.

@alcaeus
Copy link
Member

alcaeus commented Nov 8, 2024

start_date is not the correct field path, it would be input_params.start_date. Off the top of my head I'm not sure if this will work, as you're not embedding a model but "only" storing unstructured data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants