Skip to content

Commit

Permalink
Merge pull request #47 from tikkibar/master
Browse files Browse the repository at this point in the history
Support for standalone eloquent
  • Loading branch information
calebporzio authored Dec 28, 2019
2 parents d942b89 + 9922231 commit 4876192
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
}
],
"require": {
"illuminate/database": "~5.6.0|~5.7.0|~5.8.0|^6.0.0"
"illuminate/database": "~5.6.0|~5.7.0|~5.8.0|^6.0.0",
"illuminate/events": "~5.6.0|~5.7.0|~5.8.0|^6.0.0"
},
"require-dev": {
"orchestra/testbench": "3.8.*",
Expand Down
8 changes: 7 additions & 1 deletion src/HasParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

namespace Parental;

use Illuminate\Support\Str;
use ReflectionClass;
use Illuminate\Support\Str;
use Illuminate\Events\Dispatcher;

trait HasParent
{
public $hasParent = true;

public static function bootHasParent()
{
// This adds support for using Parental with standalone Eloquent, outside a normal Laravel app.
if (static::getEventDispatcher() === null) {
static::setEventDispatcher(new Dispatcher());
}

static::creating(function ($model) {
if ($model->parentHasHasChildrenTrait()) {
$model->forceFill(
Expand Down

0 comments on commit 4876192

Please sign in to comment.