Skip to content

Commit

Permalink
Update BaseModel.php (#31)
Browse files Browse the repository at this point in the history
fix - collection of models not working with pluck because __isset not set in base model.
  • Loading branch information
slnw authored Oct 16, 2023
1 parent 10cd5a9 commit 9e9c151
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 9e9c151

Please sign in to comment.