fisrt
This commit is contained in:
50
app/Traits/Macroable.php
Normal file
50
app/Traits/Macroable.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Traits;
|
||||
|
||||
trait Macroable
|
||||
{
|
||||
|
||||
use \Illuminate\Support\Traits\Macroable {
|
||||
__call as macroCall;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRelationValue($key)
|
||||
{
|
||||
$relation = parent::getRelationValue($key);
|
||||
if (!$relation && static::hasMacro($key)) {
|
||||
return $this->getRelationshipFromMethod($key);
|
||||
}
|
||||
|
||||
return $relation;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
if (static::hasMacro($method)) {
|
||||
return $this->macroCall($method, $parameters);
|
||||
}
|
||||
|
||||
return parent::__call($method, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
*/
|
||||
public static function __callStatic($method, $parameters)
|
||||
{
|
||||
return parent::__callStatic($method, $parameters);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user