Skip to content

Commit

Permalink
Add a fluent way to send route variables to DataTable service class.
Browse files Browse the repository at this point in the history
  • Loading branch information
yajra committed Jan 26, 2017
1 parent b2bbc19 commit a8929e4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Services/DataTable.php
Expand Up @@ -71,6 +71,13 @@ abstract class DataTable implements DataTableContract, DataTableButtonsContract
*/
protected $filename = '';

/**
* Custom attributes set on the class.
*
* @var array
*/
protected $attributes = [];

/**
* DataTable constructor.
*
Expand Down Expand Up @@ -360,6 +367,39 @@ public function addScope(DataTableScopeContract $scope)
return $this;
}

/**
* Set a custom class attribute.
*
* @param mixed $key
* @param mixed|null $value
* @return $this
*/
public function with($key, $value = null)
{
if (is_array($key)) {
$this->attributes = array_merge($this->attributes, $key);
} else {
$this->attributes[$key] = $value;
}

return $this;
}

/**
* Dynamically retrieve the value of an attribute.
*
* @param string $key
* @return mixed|null
*/
public function __get($key)
{
if (array_key_exists($key, $this->attributes)) {
return $this->attributes[$key];
}

return null;
}

/**
* Apply query scopes.
*
Expand Down

0 comments on commit a8929e4

Please sign in to comment.