Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Aug 19, 2023
1 parent 93e25b8 commit 479ad35
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/Console/Commands/ObserverMakeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace AnourValar\EloquentValidation\Console\Commands;

class ObserverMakeCommand extends \Illuminate\Foundation\Console\ObserverMakeCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'make:observer-validation';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Create a new observer class [eloquent-validation]';

/**
* {@inheritDoc}
* @see \Illuminate\Foundation\Console\ModelMakeCommand::getStub()
*/
protected function getStub()
{
if ($this->option('model')) {
return __DIR__.'/../../resources/observer.stub';
}

return parent::getStub();
}
}
4 changes: 3 additions & 1 deletion src/Features/ManyToManyTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ protected function onChangedM2M(Model $model, string $column, string $relation,
$sync = [];

if ($model->exists) {
foreach ((array) $model->$column as $value) {
foreach ((array) $model->$column as $name => $value) {
if (! is_null($key)) {
$sync[] = $value[$key];
} elseif (is_array($value)) {
$sync[] = $name;
} else {
$sync[] = $value;
}
Expand Down
1 change: 1 addition & 0 deletions src/Providers/EloquentValidationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function boot()
$this->commands([
\AnourValar\EloquentValidation\Console\Commands\ModelMakeCommand::class,
\AnourValar\EloquentValidation\Console\Commands\ModelValidateCommand::class,
\AnourValar\EloquentValidation\Console\Commands\ObserverMakeCommand::class,
]);
}
}
Expand Down
96 changes: 96 additions & 0 deletions src/resources/observer.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace {{ namespace }};

use {{ namespacedModel }};

class {{ class }}
{
/**
* Handle the "saving" event.
*
* @param \{{ namespacedModel }} $model
* @return mixed
*/
public function saving({{ model }} $model)
{

}

/**
* Handle the "creating" event.
*
* @param \{{ namespacedModel }} $model
* @return mixed
*/
public function creating({{ model }} $model)
{

}

/**
* Handle the "updating" event.
*
* @param \{{ namespacedModel }} $model
* @return mixed
*/
public function updating({{ model }} $model)
{

}

/**
* Handle the "created" event.
*
* @param \{{ namespacedModel }} $model
* @return void
*/
public function created({{ model }} $model)
{

}

/**
* Handle the "updated" event.
*
* @param \{{ namespacedModel }} $model
* @return void
*/
public function updated({{ model }} $model)
{

}

/**
* Handle the "saved" event.
*
* @param \{{ namespacedModel }} $model
* @return void
*/
public function saved({{ model }} $model)
{

}

/**
* Handle the "deleting" event.
*
* @param \{{ namespacedModel }} $model
* @return mixed
*/
public function deleting({{ model }} $model)
{

}

/**
* Handle the "deleted" event.
*
* @param \{{ namespacedModel }} $model
* @return void
*/
public function deleted({{ model }} $model)
{

}
}

0 comments on commit 479ad35

Please sign in to comment.