Skip to content

Commit

Permalink
allow attach method to accept many files
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 6, 2020
1 parent 2f0955d commit 1bb7ad6
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,22 @@ public function asForm()
/**
* Attach a file to the request.
*
* @param string $name
* @param string|array $name
* @param string $contents
* @param string|null $filename
* @param array $headers
* @return $this
*/
public function attach($name, $contents, $filename = null, array $headers = [])
public function attach($name, $contents = '', $filename = null, array $headers = [])
{
if (is_array($name)) {
foreach ($name as $file) {
$this->attach(...$file);
}

return $this;
}

$this->asMultipart();

$this->pendingFiles[] = array_filter([
Expand All @@ -200,21 +208,6 @@ public function attach($name, $contents, $filename = null, array $headers = [])

return $this;
}

/**
* Attach multiple files to the request.
*
* @param array $files
* @return $this
*/
public function attachMany(array $files)
{
foreach ($files as $file) {
$this->attach(...$file);
}

return $this;
}

/**
* Indicate the request is a multi-part form request.
Expand Down

0 comments on commit 1bb7ad6

Please sign in to comment.