Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

afoysal's avatar

HTTP Request Manipulation

How can I remove $request['password'] from $request->all() ?

Thanks

0 likes
4 replies
Nakov's avatar

Just use:

$request->except(['password']);

And here the documentation on how to retrieve input from the request.

2 likes
afoysal's avatar

@nakov , I am using below code

if($request['password'] = '') {
       $request->except(['password']);
    } 
    $result = User::create($request->all());

But I am getting below error

enter image description here

Nakov's avatar
Nakov
Best Answer
Level 73

The line that I gave you does not deletes the password, but gets all the data except the password from the Request.. so you just need this:

$result = User::create($request->except(['password']));

OR in your if statement, compare if the password is empty.. you are setting it's value to be empty.

if($request['password'] = '')

Should be this

if($request['password'] === '')

AND $request->except does not deletes the password from the array, it just excludes that one from the RESULT.

Snapey's avatar

alternate using ternary

$result = User::create($request->password == '' ?
                    $request->except(['password']) :
                    $request->all());

1 like

Please or to participate in this conversation.