-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathParentModel.php
33 lines (26 loc) · 1014 Bytes
/
ParentModel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
namespace Tests\Stubs\HasManyWithInverse;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Stayallive\Laravel\Eloquent\Relations\HasHasManyWithInverseRelation;
/**
* @property int $id
* @property \Illuminate\Database\Eloquent\Collection $children
* @property \Illuminate\Database\Eloquent\Collection $childrenDefaultInverse
*/
class ParentModel extends Model
{
use HasHasManyWithInverseRelation;
public $timestamps = [];
protected $table = 'test_hasmanywithinverse_parents';
protected $guarded = [];
public function children(): HasMany
{
// The `parent` argument (second) is the name of the inverse relationship as defined in the ChildModel
return $this->hasManyWithInverse(ChildModel::class, 'parent', 'parent_id');
}
public function childrenDefaultInverse(): HasMany
{
return $this->hasManyWithInverse(ChildModel::class, null, 'parent_id');
}
}