Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

adding field to array on condition laravel

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,
    ];
 
PREVIOUS NEXT
Tagged: #adding #field #array #condition #laravel
ADD COMMENT
Topic
Name
7+2 =