Add BaseModel with stricter attribute existence checking

This commit is contained in:
2018-07-29 16:37:11 +02:00
parent 72ddd75023
commit f1529b3b8e
10 changed files with 53 additions and 23 deletions
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class BaseModel extends Model
{
public function getAttribute($key)
{
if (! $key) {
throw new \LogicException("No attribute ".var_export($key, true));
}
return parent::getAttribute($key);
}
/**
* Get a relationship.
*
* @param string $key
* @return mixed
*/
public function getRelationValue($key)
{
if (!method_exists($this, $key)) {
throw new \LogicException("No attribute or relation ".var_export($key, true));
}
return parent::getRelationValue($key);
}
}