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

[5.0] File upload is broken when submitting a form without selecting a file. #6423

Closed
wants to merge 4 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,19 @@ public static function createFromBase(SymfonyRequest $request)
{
if ($request instanceof static) return $request;

$files = [];
foreach ($request->files->all() as $index => $file) {
if (null !== $file)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use: $file !== null. No yoda conditions please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm noob yet, but I desire to get better, and I'm very glad to learn from you the NOT yoda condition for this case!
Please @GrahamCampbell, teach me the right way to do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathanpmartins Yound Padawan, do this instead:
if ($file !== null)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yoda conditions are a symfony standard. Laravel doesn't use them. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ow...yeah, now I understand that. Thank you very much!!

{
$files[$index] = $file;
}
}

return (new static)->duplicate(

$request->query->all(), $request->request->all(), $request->attributes->all(),

$request->cookies->all(), $request->files->all(), $request->server->all()
$request->cookies->all(), $files, $request->server->all()
);
}

Expand Down