Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Feb 23, 2024
1 parent d55198a commit 4c1aad6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 201 deletions.
30 changes: 11 additions & 19 deletions actions.md
Expand Up @@ -87,30 +87,14 @@ $action->authorize(static function (Request $request): bool {

### Visibility

You may show or hide actions based on the current resource view. For example, some actions might be visible on the index page, while others should be hidden. You can easily customize the action visibility logic using the `visibleOn` and `hiddenOn` methods:
You may show or hide actions based on the current resource view. For example, some actions might be visible on the `index` page, while others should be hidden. You can easily customize the action visibility logic using the `visibleOn` and `hiddenOn` methods:

```php
$action->visibleOn(static function (Request $request): bool {
return $request->user()->can('batchPublish', Post::class);
});

$action->hiddenOn(static function (Request $request): bool {
return $request->user()->cannot('batchPublish', Post::class);
});
```

Also, you can use the built-in methods as well:

```php
$action->visibleOnIndex();
$action->visibleOnShow();
$field->visibleOn(['index', 'show']);

$action->hiddenOnIndex();
$action->hiddenOnShow();
$field->hiddenOn(['update', 'create']);
```

> Note, actions are using the `ResolvesVisibility` trait, but methods like `visibleOnUpdate()` have no effect.
### Destructive Actions

You may mark an action as destructive. That means, the `Run` button that performs the action becomes red, indicating it is a dangerous action to run.
Expand All @@ -126,3 +110,11 @@ You may mark an action as confirmable. That means, when pressing the `Run` butto
```php
$action->confirmable();
```

### Standalone Actions

You may mark an action as standalone. That means, the action does not need any selected models. Also, the `$models` collection in the `handle` method will be empty.

```php
$action->standalone();
```
5 changes: 5 additions & 0 deletions bazar.md
@@ -0,0 +1,5 @@
---
title: "Bazar"
github: "https://github.com/conedevelopment/root-docs/blob/master/bazar.md"
order: 11
---
2 changes: 1 addition & 1 deletion contribution.md
@@ -1,5 +1,5 @@
---
title: "Contributing to Root"
github: "https://github.com/conedevelopment/root-docs/blob/master/contribution.md"
order: 11
order: 12
---
4 changes: 1 addition & 3 deletions core-concepts.md
Expand Up @@ -16,6 +16,4 @@ However, it comes with a price: Root is scoped to small, medium-sized projects:

## Comparing to other packages, solutions

Root is heavily inspired by [Symfony EasyAdmin](https://symfony.com/bundles/EasyAdminBundle/current/index.html) and [Laravel Nova](https://nova.laravel.com/).

Root is targeting smaller applications and offers simpler and faster integration into your running or fresh application. But for very large applications you may consider using Nova. Nova has a big community and first-party support since it's maintained by the Laravel team. Also, it has some features (Queueable Actions, Vapor and Scout support for example) that we don't and probably won't support in the future.
Root is targeting smaller applications and offers simpler and faster integration into your running or fresh application.
74 changes: 12 additions & 62 deletions fields.md
Expand Up @@ -24,15 +24,12 @@ use Illuminate\Http\Request;

/**
* Define the fields for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request): array
{
return array_merge(parent::fields($request), [
return [
Text::make(__('Title'), 'title'),
]);
];
}
```

Expand All @@ -41,17 +38,14 @@ Alternatively, you can use `withFields` method on an object that resolves action
```php
use App\Root\Fields\Text;
use Illuminate\Http\Request;
use Cone\Root\Support\Collections\Fields;

$resource->withFields(static function (Request $request, Fields $fields): Fields {
return $fields->merge([
$resource->withFields(static function (Request $request): array {
return [
Text::make(__('Title'), 'title'),
]);
];
});
```

> You can also pass an `array` instead of a `Closure`. In that case the array will be merged into the collection.
### Configuration

### Value Resolution
Expand All @@ -66,7 +60,7 @@ use Illuminate\Databsase\Eloquent\Model;
use Illuminate\Http\Request;

Text::make('Title')
->default(static function (Request $request, Model $model, mixed $value): string {
->value(static function (Request $request, Model $model, mixed $value): string {
return is_null($value) ? 'foo' : $value;
});
```
Expand All @@ -81,10 +75,11 @@ You may define custom value formatters for the field values. In that case you ca
use Cone\Root\Fields\Number;
use Illuminate\Databsase\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Number;

Number::make('Price')
->format(static function (Request $request, Model $model, mixed $value): string {
return sprintf('%d USD', $value);
return Number::currency($value);
});
```

Expand All @@ -103,11 +98,6 @@ class CustomField extends Field
{
/**
* Hydrate the model.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Model $model
* @param mixed $value
* @return void
*/
public function hydrate(Request $request, Model $model, mixed $value): void
{
Expand Down Expand Up @@ -157,59 +147,21 @@ $field->authorize(static function (Request $request, ?Model $model = null, ?Mode
### Visibility

You may show or hide fields based on the current resource view. For example, some fields might be visible on the index page, while others should be hidden. You can easily customize the field visibility logic using the `visible` method:
You may show or hide fields based on the current resource view. For example, some fields might be visible on the `index` page, while others should be hidden. You can easily customize the action visibility logic using the `visibleOn` and `hiddenOn` methods:

```php
use Illuminate\Http\Request;

$field->visibleOn(static function (Request $request): bool {
return $request->user()->isAdmin();
});
$field->visibleOn(['index', 'show']);

$field->hiddenOn(static function (Request $request): bool {
return ! $request->user()->isAdmin();
});
```

Also, you can use the built-in methods as well. They are enough in most of the cases:

```php
$field->visibleOnIndex();
$field->visibleOnCreate();
$field->visibleOnShow();
$field->visibleOnUpdate();
$field->visibleOnDisplay();
$field->visibleOnForm();

$field->hiddenOnIndex();
$field->hiddenOnCreate();
$field->hiddenOnShow();
$field->hiddenOnUpdate();
$field->hiddenOnDisplay();
$field->hiddenOnForm();
```

You can also pass a `Closure` to any of the listed methods, to fully customize the visibility logic:

```php
use Illuminate\Http\Request;

$this->visible(static function (Request $request): bool {
return $request->user()->can('attachTag', Post::class);
});

$this->hidden(static function (Request $request): bool {
return $request->user()->cannot('attachTag', Post::class);
});
$field->hiddenOn(['update', 'create']);
```

### Validation

You may define validation rules for your field instances. To do so, you can call the `rules`, `createRules` and `updateRules` on the field instance:

```php
use Illuminate\Http\Request;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;

$field->rules(['string', 'required'])
Expand Down Expand Up @@ -251,8 +203,6 @@ $field->searchable(false);

### ID

### Json

### Media

### Number
Expand Down
43 changes: 3 additions & 40 deletions filters.md
Expand Up @@ -24,9 +24,6 @@ use Illuminate\Http\Request;

/**
* Define the filters for the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function filters(Request $request): array
{
Expand All @@ -43,15 +40,13 @@ use App\Root\Filters\Category;
use Cone\Root\Support\Collections\Filters;
use Illuminate\Http\Request;

$resource->withFilters(static function (Request $request, Filters $filters): Filters {
return $filters->merge([
$resource->withFilters(static function (Request $request): array {
return [
Category::make(),
]);
];
});
```

> You can also pass an `array` instead of a `Closure`. In that case the array will be merged into the collection.
## Configuration

### Options
Expand All @@ -69,11 +64,6 @@ class Category extends Filter
{
/**
* Apply the filter on the query.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Builder
*/
public function apply(Request $request, Builder $query, mixed $value): Builder
{
Expand All @@ -82,9 +72,6 @@ class Category extends Filter

/**
* Get the filter options.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function options(Request $request): array
{
Expand All @@ -102,30 +89,6 @@ Also, you may configure a select filter with multiple selectable choices. To do
Category::make()->multiple();
```

### Custom Components

By default, filters use the `Select` form component, however you can use any component you want. You may also register your own custom component as well:

```js
document.addEventListener('root:booting', ({ detail }) => {
detail.app.component('CustomFilter', require('./Components/CustomFilter').defaul);
});
```

```php
use Cone\Root\Filters\Filter;

class CustomFilter extends Filter
{
/**
* The Vue component.
*
* @var string|null
*/
protected ?string $component = 'CustomFilter';
}
```

### Functional Filters

Also, in some cases you may interact with the Query Builder in a filter, but you don't want to render any component for it on the front-end. In that case, you may use functional components. For functional components the `$component` property is set to `null`:
Expand Down

0 comments on commit 4c1aad6

Please sign in to comment.