Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit e0c810e

Browse files
committed
fix(5.4) : make compatible with Laravel 5.4
Resolves: #126
1 parent 7fc362d commit e0c810e

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/EloquentSubscriber.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace AlgoliaSearch\Laravel;
44

5+
use Illuminate\Database\Eloquent\Model;
6+
57
class EloquentSubscriber
68
{
79
private $modelHelper;
@@ -11,8 +13,10 @@ public function __construct(ModelHelper $modelHelper)
1113
$this->modelHelper = $modelHelper;
1214
}
1315

14-
public function saved($model)
16+
public function saved($eventName, $payload = null)
1517
{
18+
$model = $this->getModelFromParams($eventName, $payload);
19+
1620
if (!$this->modelHelper->isAutoIndex($model)) {
1721
return true;
1822
}
@@ -29,8 +33,10 @@ public function saved($model)
2933
return true;
3034
}
3135

32-
public function deleted($model)
36+
public function deleted($eventName, $payload = null)
3337
{
38+
$model = $this->getModelFromParams($eventName, $payload);
39+
3440
if (!$this->modelHelper->isAutoDelete($model)) {
3541
return true;
3642
}
@@ -43,6 +49,23 @@ public function deleted($model)
4349
return true;
4450
}
4551

52+
/**
53+
* @param string|Model $eventName
54+
* @param array|null $payload
55+
*
56+
* @return Model
57+
*/
58+
private function getModelFromParams($eventName, $payload = null)
59+
{
60+
if($eventName instanceof Model) {
61+
// Laravel < 5.4
62+
return $eventName;
63+
}
64+
65+
// Laravel >= 5.4
66+
return $payload[0];
67+
}
68+
4669
public function subscribe($events)
4770
{
4871
$events->listen('eloquent.saved*', '\AlgoliaSearch\Laravel\EloquentSubscriber@saved');

0 commit comments

Comments
 (0)