Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions src/Actions/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Binaryk\LaravelRestify\Http\Requests\ActionRequest;
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
use Binaryk\LaravelRestify\Models\ActionLog;
use Binaryk\LaravelRestify\Models\Concerns\HasActionLogs;
use Binaryk\LaravelRestify\Restify;
use Binaryk\LaravelRestify\Traits\AuthorizedToSee;
use Binaryk\LaravelRestify\Traits\Make;
Expand Down Expand Up @@ -82,8 +82,8 @@ public function uriKey()
/**
* Determine if the action is executable for the given request.
*
* @param Request $request
* @param Model $model
* @param Request $request
* @param Model $model
* @return bool
*/
public function authorizedToRun(Request $request, $model)
Expand All @@ -94,7 +94,7 @@ public function authorizedToRun(Request $request, $model)
/**
* Set the callback to be run to authorize running the action.
*
* @param Closure $callback
* @param Closure $callback
* @return $this
*/
public function canRun(Closure $callback)
Expand All @@ -107,8 +107,8 @@ public function canRun(Closure $callback)
/**
* Get the payload available on the action.
*
* @deprecated Use rules instead
* @return array
* @deprecated Use rules instead
*/
public function payload(): array
{
Expand All @@ -128,7 +128,7 @@ public function rules(): array
/**
* Make current action being standalone. No model query will be performed.
*
* @param bool $standalone
* @param bool $standalone
* @return self
*/
public function standalone(bool $standalone = true): self
Expand Down Expand Up @@ -167,7 +167,11 @@ public function handleRequest(ActionRequest $request)
Transaction::run(function () use ($models, $request, &$response) {
$response = $this->handle($request, $models);

$models->each(fn (Model $model) => ActionLog::forRepositoryAction($this, $model, $request->user())->save());
$models->each(function (Model $model) use ($request) {
if (in_array(HasActionLogs::class, class_uses_recursive($model), true)) {
Restify::actionLog()::forRepositoryAction($this, $model, $request->user())->save();
}
});
});
});
} else {
Expand All @@ -179,11 +183,13 @@ public function handleRequest(ActionRequest $request)
})->firstOrFail()
);

Restify::actionLog()::forRepositoryAction(
$this,
$model,
$request->user()
)->save();
if (in_array(HasActionLogs::class, class_uses_recursive($model), true)) {
Restify::actionLog()::forRepositoryAction(
$this,
$model,
$request->user()
)->save();
}
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/Filters/MatchesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function inQuery(RestifyRequest $request): self
{
return $this->filter(function (MatchFilter $filter) use ($request) {
$possibleKeys = collect([
$filter->getColumn(),
"-{$filter->getColumn()}",
$filter->column(),
"-{$filter->column()}",
]);

if ($filters = collect($request->input('filter', []))) {
Expand All @@ -60,7 +60,7 @@ public function inQuery(RestifyRequest $request): self
}
}

return $request->has("-{$filter->getColumn()}") || $request->has($filter->getColumn());
return (bool) ($request->query("-{$filter->column()}") || $request->query($filter->column()));
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Http/Requests/ActionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function builder(Action $action, int $size): Builder
->latest($this->model()->getKeyName());
}

public function collectRepositories(Action $action, $count, Closure $callback)
public function collectRepositories(Action $action, $count, Closure $callback): array
{
$output = [];

Expand Down