-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
681f92e
commit 356c657
Showing
3 changed files
with
90 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace A17\EdgeFlush\Models; | ||
|
||
use Illuminate\Support\Facades\Event; | ||
use Illuminate\Queue\SerializesModels; | ||
use App\Twill\Capsules\People\Models\Person; | ||
use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | ||
|
||
class Builder extends EloquentBuilder | ||
{ | ||
use SerializesModels; | ||
|
||
/** | ||
* Update records in the database. | ||
* | ||
* @param array $values | ||
* @return int | ||
*/ | ||
public function update(array $values) | ||
{ | ||
if (count($this->model->getAttributes()) > 0) | ||
{ | ||
return; | ||
} | ||
|
||
$eventData = json_encode(['model' => get_class($this->model), 'attributes' => $this->compileAttributesFromQuery($values), 'updates' => $values]); | ||
|
||
Event::dispatch('eloquent.builder.updating: ' . get_class($this->model), $eventData); | ||
|
||
$value = $this->toBase()->update($this->addUpdatedAtColumn($values)); | ||
|
||
Event::dispatch('eloquent.builder.updated: ' . get_class($this->model), $eventData); | ||
} | ||
|
||
public function compileAttributesFromQuery(array $values): array | ||
{ | ||
$data = []; | ||
|
||
foreach($this->query->wheres as $where) | ||
{ | ||
if ($where['type'] == 'Basic') | ||
{ | ||
if ($where['column'] !== 'id' || $where['value'] != 0) { | ||
$data[$where['column']] = $where['value']; | ||
} | ||
} | ||
} | ||
|
||
return array_merge($data, $values); | ||
} | ||
} |