Update BaseModel.php (#31)

fix - collection of models not working with pluck because __isset not set in base model.
This commit is contained in:
Slaine Willey
2023-10-16 13:09:36 +05:00
committed by GitHub
parent 10cd5a9f73
commit 9e9c151cc6
+25
View File
@@ -72,7 +72,32 @@ class BaseModel
* @var string
*/
protected $connection = Connection::DEFAULT_NAME;
/**
* Determine if an attribute or relation exists on the model.
* The __isset magic method is triggered by calling isset() or empty() on inaccessible properties.
*
* @param string $key The name of the attribute or relation.
* @return bool True if the attribute or relation exists, false otherwise.
*/
public function __isset($key)
{
if (array_key_exists($key, $this->attributes)) {
return true;
}
$accessor = 'get' . Str::studly($key) . 'Attribute';
if (method_exists($this, $accessor)) {
return true;
}
if (array_key_exists($key, $this->relations)) {
return true;
}
return false;
}
/**
* Get the table associated with the model.
*