开发者

Laravel Eloquent model works like referencing when assigning to another variable

开发者 https://www.devze.com 2022-12-07 20:38 出处:网络
I am doing this in laravel and getting unexpected result $remitter = Remitter::where(\'mobile\', \'9946617986\')->first();

I am doing this in laravel and getting unexpected result


$remitter = Remitter::where('mobile', '9946617986')->first();

$new = $remitter;
$new->rohan = 'Rohan';

unset($remitter->rohan);
dd($new);

here I just grabbed one eloquent object $remitter and then I pushed it in another variable $new Now when I created one tag named "rohan" on new it gets added into $remit开发者_JS百科ter too

now when I unset $remitter->rohan

rohan tag was also removed from $new too why this is happening ?

why this is working like referencing ?

any Ideas


$new = collect($remitter->toArray());
0

精彩评论

暂无评论...
验证码 换一张
取 消