Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Oct 5, 2023
1 parent c11071a commit ddf907c
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Columns/RowActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
2 changes: 1 addition & 1 deletion src/Http/Controllers/ResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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!')));
Expand Down
6 changes: 0 additions & 6 deletions src/Http/Controllers/ResourceFieldController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
Expand Down
86 changes: 60 additions & 26 deletions stubs/UserResource.stub
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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), [
//
]);
}
}

0 comments on commit ddf907c

Please sign in to comment.