Skip to content

Commit

Permalink
## 3.6.0 - 2022-02-18
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Feb 17, 2022
1 parent c1fb624 commit f03209a
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 22 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to `crud` will be documented in this file

## 3.6.0 - 2022-02-18

### Changed

- Passing model type in default actions

## 3.5.0 - 2022-02-10

### Changed
Expand Down
8 changes: 4 additions & 4 deletions src/CrudScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function action(ActionRequest $request)
*/
public function update(UpdateRequest $request)
{
$request->resource()->onSave($request, $request->findModelOrFail());
$request->resource()->save($request, $request->findModelOrFail());

Toast::info($this->resource::updateToastMessage());

Expand All @@ -176,7 +176,7 @@ public function update(UpdateRequest $request)
*/
public function delete(DeleteRequest $request)
{
$request->resource()->onDelete(
$request->resource()->delete(
$request->findModelOrFail()
);

Expand All @@ -194,7 +194,7 @@ public function delete(DeleteRequest $request)
*/
public function forceDelete(ForceDeleteRequest $request)
{
$request->resource()->onForceDelete(
$request->resource()->forceDelete(
$request->findModelOrFail()
);

Expand All @@ -210,7 +210,7 @@ public function forceDelete(ForceDeleteRequest $request)
*/
public function restore(RestoreRequest $request)
{
$request->resource()->onRestore(
$request->resource()->restore(
$request->findModelOrFail()
);

Expand Down
58 changes: 41 additions & 17 deletions src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,23 +386,40 @@ public function modelQuery(ResourceRequest $request, Model $model): Builder
/**
* Action to query models list
*
* @param Model $model
* @param \Orchid\Crud\ResourceRequest $request
* @param Model $model
*
* @return Model $model
* @return \Illuminate\Database\Eloquent\Builder $model
*/
public function paginationQuery(ResourceRequest $request, Model $model): Builder
{
return $model->query();
}

/**
* Determine if this resource uses soft deletes.
*
* @return bool
*/
public static function softDeletes(): bool
{
return in_array(SoftDeletes::class, class_uses_recursive(static::$model), true);
}

/**
* Action to create and update the model
*
* @param ResourceRequest $request
* @param Model $model
*/
public function onSave(ResourceRequest $request, Model $model)
public function save(ResourceRequest $request, Model $model): void
{
if (method_exists(static::class, 'onSave')) {
static::onSave($request, $model);

return;
}

$model->forceFill($request->all())->save();
}

Expand All @@ -413,28 +430,30 @@ public function onSave(ResourceRequest $request, Model $model)
*
* @throws Exception
*/
public function onDelete(Model $model)
public function delete(Model $model): void
{
$model->delete();
}
if (method_exists(static::class, 'onDelete')) {
static::onDelete($model);

/**
* Determine if this resource uses soft deletes.
*
* @return bool
*/
public static function softDeletes(): bool
{
return in_array(SoftDeletes::class, class_uses_recursive(static::$model), true);
return;
}

$model->delete();
}

/**
* Action to restore a model
*
* @param Model $model
*/
public function onRestore(Model $model)
public function restore(Model $model): void
{
if (method_exists(static::class, 'onRestore')) {
static::onRestore($model);

return;
}

$model->restore();
}

Expand All @@ -445,9 +464,14 @@ public function onRestore(Model $model)
*
* @throws Exception
*/
public function onForceDelete(Model $model)
public function forceDelete(Model $model): void
{
// Force deleting a single model instance...
if (method_exists(self::class, 'onForceDelete')) {
static::onForceDelete($model);

return;
}

$model->forceDelete();
}
}
2 changes: 1 addition & 1 deletion src/Screens/CreateScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function save(CreateRequest $request)
{
$model = $request->model();

$request->resource()->onSave($request, $model);
$request->resource()->save($request, $model);

Toast::info($this->resource::createToastMessage());

Expand Down

0 comments on commit f03209a

Please sign in to comment.