diff --git a/src/Columns/RowActions.php b/src/Columns/RowActions.php index cb2e0ca3..bf30740c 100644 --- a/src/Columns/RowActions.php +++ b/src/Columns/RowActions.php @@ -27,7 +27,7 @@ public function newCell(Model $model): Cell public function toCell(Model $model): Cell { return $this->newCell($model)->value(function (Request $request, Model $model): string { - return ''; + return $this->table->modelUrl($model); }); } } diff --git a/src/Http/Controllers/ResourceController.php b/src/Http/Controllers/ResourceController.php index 00e93e6f..48844362 100644 --- a/src/Http/Controllers/ResourceController.php +++ b/src/Http/Controllers/ResourceController.php @@ -64,7 +64,7 @@ public function store(Request $request, Resource $resource): RedirectResponse $model = $resource->getModelInstance(); - $resource->toForm($request, $model)->handle($request); + $resource->handleFormRequest($request, $model); return Redirect::to($resource->modelUrl($model)) ->with('alerts.resource-created', Alert::success(__('The resource has been created!'))); diff --git a/src/Http/Controllers/ResourceFieldController.php b/src/Http/Controllers/ResourceFieldController.php index afb5e99c..d976a061 100644 --- a/src/Http/Controllers/ResourceFieldController.php +++ b/src/Http/Controllers/ResourceFieldController.php @@ -14,12 +14,6 @@ class ResourceFieldController extends Controller */ public function __invoke(Request $request, Resource $resource): JsonResponse { - $model = $request->has('model') - ? $resource->resolveRouteBinding($request, $request->query('model')) - : $resource->getModelInstance(); - - $form = $resource->toForm($request, $model); - $field = $resource->findField( $request, $request->path() ); diff --git a/stubs/UserResource.stub b/stubs/UserResource.stub index 0060d291..29c7a143 100644 --- a/stubs/UserResource.stub +++ b/stubs/UserResource.stub @@ -2,11 +2,11 @@ namespace App\Root\Resources; -use Cone\Root\Fields\Fields; -use Cone\Root\Interfaces\Form; +use Cone\Root\Columns\Column; +use Cone\Root\Columns\ID; +use Cone\Root\Fields\Email; +use Cone\Root\Fields\Text; use Cone\Root\Resources\Resource; -use Cone\Root\Columns\Columns; -use Cone\Root\Table\Table; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; use Illuminate\Validation\Rule; @@ -19,34 +19,68 @@ class UserResource extends Resource protected string $icon = 'users'; /** - * {@inheritdoc} + * Define the columns. */ - public function toTable(Request $request): Table + public function columns(Request $request): array { - return parent::toTable($request) - ->withColumns(static function (Request $request, Columns $columns): void { - $columns->id(); - $columns->text(__('Name'), 'name'); - $columns->text(__('Email'), 'email'); - }); + return array_merge(parent::columns($request), [ + ID::make(), + + Column::make(__('Name'), 'name') + ->searchable() + ->sortable(), + + Column::make(__('Email'), 'email') + ->searchable() + ->sortable(), + ]); + } + + /** + * Define the fields. + */ + public function fields(Request $request): array + { + return array_merge(parent::fields($request), [ + Text::make(__('Name'), 'name') + ->rules(['required', 'string', 'max:256']), + + Email::make(__('Email'), 'email') + ->rules(['required', 'string', 'email', 'max:256']) + ->createRules(['unique:users']) + ->updateRules(static function (Request $request, Model $model): array { + return [Rule::unique('users')->ignoreModel($model)]; + }), + ]); + } + + /** + * Define the filters. + */ + public function filters(Request $request): array + { + return array_merge(parent::filters($request), [ + // + ]); + } + + /** + * Define the actions. + */ + public function actions(Request $request): array + { + return array_merge(parent::actions($request), [ + // + ]); } /** - * {@inheritdoc} + * Define the widgets for the resource. */ - public function toForm(Request $request): Form + public function widgets(Request $request): array { - return parent::toForm($request) - ->withFields(static function (Request $request, Fields $fields): void { - $fields->text(__('Name'), 'name') - ->rules(['required', 'string', 'max:256']); - - $fields->email(__('Email'), 'email') - ->rules(['required', 'string', 'email', 'max:256']) - ->createRules(['unique:users']) - ->updateRules(static function (Request $request, Model $model): array { - return [Rule::unique('users')->ignoreModel($model)]; - }); - }); + return array_merge(parent::widgets($request), [ + // + ]); } }