Skip to content

Commit

Permalink
add support to call underlying model methods (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinushasilva authored and bsormagec committed Dec 21, 2019
1 parent 684c46a commit a107e47
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Prettus/Repository/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,24 @@ public function firstOrNew(array $attributes = []);
* @return mixed
*/
public function firstOrCreate(array $attributes = []);

/**
* Trigger static method calls to the model
*
* @param $method
* @param $arguments
*
* @return mixed
*/
public static function __callStatic($method, $arguments);

/**
* Trigger method calls to the model
*
* @param string $method
* @param array $arguments
*
* @return mixed
*/
public function __call($method, $arguments);
}
29 changes: 29 additions & 0 deletions src/Prettus/Repository/Eloquent/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -1068,4 +1068,33 @@ public function parserResult($result)

return $result;
}

/**
* Trigger static method calls to the model
*
* @param $method
* @param $arguments
*
* @return mixed
*/
public static function __callStatic($method, $arguments)
{
return call_user_func_array([new static(), $method], $arguments);
}

/**
* Trigger method calls to the model
*
* @param string $method
* @param array $arguments
*
* @return mixed
*/
public function __call($method, $arguments)
{
$this->applyCriteria();
$this->applyScope();

return call_user_func_array([$this->model, $method], $arguments);
}
}

0 comments on commit a107e47

Please sign in to comment.