Skip to content

Commit 8ac006a

Browse files
committed
wip
1 parent 79c4b80 commit 8ac006a

File tree

3 files changed

+30
-61
lines changed

3 files changed

+30
-61
lines changed

core-concepts.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Product::getProxiedContract();
6161

6262
// Proxied calls to the bound instance
6363
Product::proxy()->newQuery()->where(...);
64-
Product::proxy()->variation(...);
6564

6665
// Dynamic usage of bound classes
6766
public function product()
@@ -85,8 +84,6 @@ class Addon extends Model implements Contract
8584

8685
/**
8786
* Get the proxied contract.
88-
*
89-
* @return string
9087
*/
9188
public static function getProxiedContract(): string
9289
{

fields.md

Lines changed: 29 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ public function fields(Request $request): array
3333
}
3434
```
3535

36-
Alternatively, you can use `withFields` method on an object that resolves actions. It can be useful when you just want to hook into the object for some reason.
37-
38-
```php
39-
use App\Root\Fields\Text;
40-
use Illuminate\Http\Request;
41-
42-
$resource->withFields(static function (Request $request): array {
43-
return [
44-
Text::make(__('Title'), 'title'),
45-
];
46-
});
47-
```
48-
4936
### Configuration
5037

5138
### Value Resolution
@@ -85,25 +72,18 @@ Number::make('Price')
8572

8673
### Value Hydration
8774

88-
You may define custom value hydration logic on your field class. To do so, you can easily override the default `hydrate` method:
75+
You may define custom value hydration logic on your field. To do so, use the `hydrate` method passing a `Closure`:
8976

9077
```php
91-
namespace App\Root\Fields;
92-
93-
use Cone\Root\Fields\Field;
94-
use Illuminate\Http\Request;
78+
use Cone\Root\Fields\Number;
9579
use Illuminate\Database\Eloquent\Model;
80+
use Illuminate\Http\Request;
81+
use Illuminate\Support\Number;
9682

97-
class CustomField extends Field
98-
{
99-
/**
100-
* Hydrate the model.
101-
*/
102-
public function hydrate(Request $request, Model $model, mixed $value): void
103-
{
104-
$model->setAttribute($this->name, $value);
105-
}
106-
}
83+
Number::make('Price')
84+
->hydrate(static function (Request $request, Model $model, mixed $value): void {
85+
$model->setAttribute('price', $value);
86+
});
10787
```
10888

10989
## Authorization
@@ -113,38 +93,11 @@ You may allow/disallow interaction with fields. To do so, you can call the `auth
11393
```php
11494
use Illuminate\Http\Request;
11595

116-
$field->authorize(static function (Request $request): bool {
117-
return $request->user()->can('create', Post::class);
118-
});
119-
```
120-
121-
Also, when authorizing fields, pivot fields or actions, you may have access to the models of the context:
122-
123-
```php
124-
use Illuminate\Http\Request;
125-
use Illuminate\Database\Eloquent\Model;
126-
127-
// Action or top level field
128-
$field->authorize(static function (Request $request, ?Model $model = null): bool {
129-
if (is_null($model)) {
130-
return $request->user()->can('create', Post::class);
131-
}
132-
133-
return $request->user()->can('view', $model);
134-
});
135-
136-
// Pivot field
137-
$field->authorize(static function (Request $request, ?Model $model = null, ?Model $related = null): bool {
138-
if (is_null($model) || is_null($related)) {
139-
return $request->user()->can('create', Tag::class);
140-
}
141-
142-
return $request->user()->can('attachTag', $model, $related);
96+
$field->authorize(static function (Request $request, Model $model): bool {
97+
return $request->user()->isAdmin();
14398
});
14499
```
145100

146-
> The `$model` and the `$related` parameters can be null, since they are only passed to the callback when they are available in the current authorization context.
147-
148101
### Visibility
149102

150103
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:
@@ -191,8 +144,27 @@ $field->searchable(false);
191144

192145
### Boolean
193146

147+
The `Boolean` field is typically a handler for `boolean` model attributes:
148+
149+
> Don't forget to [cast](https://laravel.com/docs/master/eloquent-mutators#attribute-casting) you model attribute as a `boolean`.
150+
151+
```php
152+
$field = Boolean::make(__('Enabled'), 'enabled');
153+
```
154+
194155
### Checkbox
195156

157+
The `Checkbox` field is typically a handler for (array of values) `json` model attributes:
158+
159+
> Don't forget to [cast](https://laravel.com/docs/master/eloquent-mutators#attribute-casting) you model attribute as a `json` or `array`.
160+
161+
```php
162+
$field = Checkbox::make(__('Permissions'), 'permissions')
163+
->options([
164+
//
165+
]);
166+
```
167+
196168
### Color
197169

198170
### Date

installation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Requirements:
1212

1313
- PHP `8.2+`
1414
- PHP `GD` and `EXIF` extensions
15-
- Laravel `^10.0`
15+
- Laravel `^11.0`
1616

1717
## Installation
1818

0 commit comments

Comments
 (0)