Question : adding field to array on condition laravel
Answered by : lokesh-ramchandani-in6l3jq294i2
return [ 'id' => $this->id, 'name' => $this->name, 'email' => $this->email, $this->mergeWhen(Auth::user()->isAdmin(), [ 'first-secret' => 'value', 'second-secret' => 'value', ]), 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ];
Source : | Last Update : Sat, 25 Dec 21