Skip to content

Commit 9e9c151

Browse files
authored
Update BaseModel.php (#31)
fix - collection of models not working with pluck because __isset not set in base model.
1 parent 10cd5a9 commit 9e9c151

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/BaseModel.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,32 @@ class BaseModel
7272
* @var string
7373
*/
7474
protected $connection = Connection::DEFAULT_NAME;
75+
76+
/**
77+
* Determine if an attribute or relation exists on the model.
78+
* The __isset magic method is triggered by calling isset() or empty() on inaccessible properties.
79+
*
80+
* @param string $key The name of the attribute or relation.
81+
* @return bool True if the attribute or relation exists, false otherwise.
82+
*/
83+
public function __isset($key)
84+
{
85+
if (array_key_exists($key, $this->attributes)) {
86+
return true;
87+
}
7588

89+
$accessor = 'get' . Str::studly($key) . 'Attribute';
90+
if (method_exists($this, $accessor)) {
91+
return true;
92+
}
93+
94+
if (array_key_exists($key, $this->relations)) {
95+
return true;
96+
}
97+
98+
return false;
99+
}
100+
76101
/**
77102
* Get the table associated with the model.
78103
*

0 commit comments

Comments
 (0)