diff --git a/src/CrudScreen.php b/src/CrudScreen.php index 15cc7da..e1f6756 100644 --- a/src/CrudScreen.php +++ b/src/CrudScreen.php @@ -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; @@ -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 @@ -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. * diff --git a/src/Resource.php b/src/Resource.php index 6c16766..64e9b13 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -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(); } /**