Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 23, 2018
1 parent 007d516 commit 5f520f3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
17 changes: 10 additions & 7 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Eloquent\Relations;

use Illuminate\Support\Str;
use InvalidArgumentException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
Expand Down Expand Up @@ -76,7 +77,7 @@ class BelongsToMany extends Relation
protected $pivotWhereIns = [];

/**
* Default values for the pivot columns.
* The default values for the pivot columns.
*
* @var array
*/
Expand Down Expand Up @@ -355,27 +356,29 @@ public function orWherePivot($column, $operator = null, $value = null)
}

/**
* Sets default value when querying or creating a new row in the pivot table.
* Set a where clause for a pivot table column.
*
* In addition, new pivot records will receive this value.
*
* @param string $column
* @param mixed $value
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function withPivotValues($column, $value = null)
public function withPivotValue($column, $value = null)
{
if (is_array($column)) {
foreach ($column as $name => $value) {
$this->withPivotValues($name, $value);
$this->withPivotValue($name, $value);
}

return $this;
}

if (is_null($value)) {
throw new \InvalidArgumentException('$value cannot be null.');
throw new InvalidArgumentException('The provided value may not be null.');
}

$this->pivotValues[] = func_get_args();
$this->pivotValues[] = compact('column', 'value');

return $this->wherePivot($column, '=', $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,8 @@ protected function baseAttachRecord($id, $timed)
$record = $this->addTimestampsToAttachment($record);
}

// Adding the default pivot values (if there is any) to the record.
foreach ($this->pivotValues as $arguments) {
list($name, $value) = $arguments;
$record[$name] = $value;
foreach ($this->pivotValues as $value) {
$record[$value['column']] = $value['value'];
}

return $record;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ public function tearDown()
m::close();
}

public function testWithPivotValuesMethodSetsWhereConditionsForFetching()
public function testwithPivotValueMethodSetsWhereConditionsForFetching()
{
$relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['touchIfTouching'])->setConstructorArgs($this->getRelationArguments())->getMock();
$relation->withPivotValues(['is_admin' => 1]);
$relation->withPivotValue(['is_admin' => 1]);
}

public function testWithPivotValuesMethodSetsDefaultArgumentsForInsertion()
public function testwithPivotValueMethodSetsDefaultArgumentsForInsertion()
{
$relation = $this->getMockBuilder('Illuminate\Database\Eloquent\Relations\BelongsToMany')->setMethods(['touchIfTouching'])->setConstructorArgs($this->getRelationArguments())->getMock();
$relation->withPivotValues(['is_admin' => 1]);
$relation->withPivotValue(['is_admin' => 1]);

$query = m::mock('stdClass');
$query->shouldReceive('from')->once()->with('club_user')->andReturn($query);
Expand Down

0 comments on commit 5f520f3

Please sign in to comment.