Skip to content

Commit

Permalink
Fixed state manager
Browse files Browse the repository at this point in the history
  • Loading branch information
tabuna committed Apr 20, 2024
1 parent 93a8632 commit 2dcd035
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
51 changes: 26 additions & 25 deletions src/CrudScreen.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Orchid\Crud\Requests\ActionRequest;
use Orchid\Crud\Requests\DeleteRequest;
Expand All @@ -19,31 +20,10 @@

abstract class CrudScreen extends Screen
{
/**
* Display header name.
*
* @var string
*/
public $name;

/**
* Display header description.
*
* @var string
*/
public $description;

/**
* @var ResourceRequest
*/
public $request;

/**
* Permission.
*
* @var string|array
*/
public $permission;
protected $request;

/**
* @var Resource
Expand All @@ -59,14 +39,35 @@ public function __construct()
$this->middleware(function ($request, $next) {
$this->request = app(ResourceRequest::class);
$this->resource = $this->request->resource();
$this->name = $this->resource::label();
$this->description = $this->resource::description();
$this->permission = $this->resource::permission();

return $next($request);
});
}

/**
* The name of the screen to be displayed in the header.
*/
public function name(): ?string
{
return $this->resource::label();
}

/**
* A description of the screen to be displayed in the header.
*/
public function description(): ?string
{
return $this->resource::description();
}

/**
* The permissions required to access this screen.
*/
public function permission(): ?iterable
{
return Arr::wrap($this->resource::permission());
}

/**
* Determine if the entity has a given ability.
*
Expand Down
6 changes: 5 additions & 1 deletion src/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ abstract class Resource
*/
public static function label(): string
{
return Str::of(static::nameWithoutResource())->snake(' ')->title()->plural();
return Str::of(static::nameWithoutResource())
->snake(' ')
->title()
->plural()
->toString();
}

/**
Expand Down

0 comments on commit 2dcd035

Please sign in to comment.