Skip to content

Commit 3ef12c6

Browse files
committed
wip
1 parent 9ceeb68 commit 3ef12c6

File tree

8 files changed

+81
-108
lines changed

8 files changed

+81
-108
lines changed

actions.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,11 @@ use Illuminate\Http\Request;
2828
public function actions(Request $request): array
2929
{
3030
return [
31-
new SendPasswordResetNotification(),
31+
new SendPasswordResetNotification,
3232
];
3333
}
3434
```
3535

36-
Alternatively, you can use `withActions` 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\Actions\SendPasswordResetNotification;
40-
use Illuminate\Http\Request;
41-
42-
$resource->withActions(static function (Request $request): array {
43-
return [
44-
new SendPasswordResetNotification(),
45-
];
46-
});
47-
```
48-
4936
## Configuration
5037

5138
### Fields

bazar.md

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Also, you may add your custom driver easily that implements the required logic o
6969
Registering gateways works almost the same as registering shipping methods. All custom drivers should extend the `Bazar\Gateway\Driver` class.
7070

7171
```php
72-
use Bazar\Gateway\Driver;
72+
use Cone\Bazar\Gateway\Driver;
7373

7474
class CreditCardDriver extends Driver
7575
{
@@ -80,7 +80,7 @@ class CreditCardDriver extends Driver
8080
Now, let's register the driver using the `Bazar\Support\Facades\Gateway` facade:
8181

8282
```php
83-
use Bazar\Support\Facades\Gateway;
83+
use Cone\Bazar\Support\Facades\Gateway;
8484

8585
Gateway::extend('credit-card', static function ($app): CreditCardDriver {
8686
return new CreditCardDriver(
@@ -102,7 +102,7 @@ The class that implements the interface must implement the `shipping` method, wh
102102
> By default, the `Bazar\Models\Order` and the `Bazar\Models\Cart` models are implementing the contract.
103103
104104
```php
105-
use Bazar\Models\Shipping;
105+
use Cone\Bazar\Models\Shipping;
106106
use Illuminate\Database\Eloquent\Relations\MorphOne;
107107

108108
public function shipping(): MorphOne
@@ -122,8 +122,8 @@ Registering shipping methods works almost the same as registering gateways metho
122122
Let's create a simple driver as an example:
123123

124124
```php
125-
use Bazar\Contracts\Shippable;
126-
use Bazar\Shipping\Driver;
125+
use Cone\Bazar\Contracts\Shippable;
126+
use Cone\Bazar\Shipping\Driver;
127127

128128
class FedexDriver extends Driver
129129
{
@@ -137,7 +137,7 @@ class FedexDriver extends Driver
137137
Now, let's register the driver using the `Bazar\Support\Facades\Shipping` facade:
138138

139139
```php
140-
use Bazar\Support\Facades\Shipping;
140+
use Cone\Bazar\Support\Facades\Shipping;
141141

142142
Shipping::extend('fedex', static function ($app): FedexDriver {
143143
return new FedexDriver(
@@ -174,14 +174,12 @@ Cart::removeItem($item->id);
174174

175175
### Taxes
176176

177-
> Before moving on, you may check the [tax documentation](/docs/tax) about managing taxes.
178-
179177
The `Cart` model uses the `Itemable` trait, which allows the model to interact with its `Taxable` models. Taxes are stored on the `Item` and `Shipping` models.
180178

181179
There are several methods to retrieve the aggregated tax for the model:
182180

183181
```php
184-
use Bazar\Support\Facades\Cart;
182+
use Cone\Bazar\Support\Facades\Cart;
185183

186184
// Aggregate the calculated taxes
187185
$tax = Cart::getModel()->getTax();
@@ -195,12 +193,10 @@ $tax = Cart::getModel()->calculateTax(false);
195193

196194
### Discounts
197195

198-
> Before moving on, you may check the [discount documentation](/docs/discount) about managing discounts.
199-
200-
Unlike TAXes, discounts are stored directly on the model as an aggregated value.
196+
Unlike Taxes, discounts are stored directly on the model as an aggregated value.
201197

202198
```php
203-
use Bazar\Support\Facades\Cart;
199+
use Cone\Bazar\Support\Facades\Cart;
204200

205201
// Get the discount attribute
206202
$tax = Cart::getModel()->getDiscount();
@@ -214,10 +210,8 @@ $tax = Cart::getModel()->calculateDiscount(false);
214210

215211
### Shipping
216212

217-
> Before moving on, you may check the [shipping documentation](/docs/shipping) about managing shipping methods.
218-
219213
```php
220-
use Bazar\Support\Facades\Cart;
214+
use Cone\Bazar\Support\Facades\Cart;
221215

222216
// Get the calculated shipping cost
223217
Cart::getModel()->shipping->getCost();
@@ -238,7 +232,7 @@ However, this behavior can be controlled by the lock/unlock mechanism. When the
238232
> Note, you may retrieve the `Cart` model using the `Cart` facade for this feature.
239233
240234
```php
241-
use Bazar\Models\Cart;
235+
use Cone\Bazar\Models\Cart;
242236

243237
$cart = Cart::first();
244238

@@ -264,7 +258,7 @@ This can be extremely useful in the checkout process. Locking the cart can make
264258
To keep the database clean, carts without owners **expire in 3 days**. To retrieve the expired carts, you may use the `expired()` query scope on the `Cart` model:
265259

266260
```php
267-
use Bazar\Models\Cart;
261+
use Cone\Bazar\Models\Cart;
268262

269263
$expired = Cart::expired()->get();
270264
```
@@ -309,8 +303,8 @@ Like shipping and payment gateway, Bazar manages multiple cart drivers as well.
309303
Registering cart drivers works almost the same as registering shipping methods or payment gateways. All custom drivers should extend the `Bazar\Cart\Driver` class, which holds one abstract method: `resolve()`.
310304

311305
```php
312-
use Bazar\Cart\Driver;
313-
use Bazar\Models\Cart;
306+
use Cone\Bazar\Cart\Driver;
307+
use Cone\Bazar\Models\Cart;
314308

315309
class TokenDriver extends Driver
316310
{
@@ -333,7 +327,7 @@ class TokenDriver extends Driver
333327
Now, let's register the driver using the `Bazar\Support\Facades\Cart` facade:
334328

335329
```php
336-
use Bazar\Support\Facades\Cart;
330+
use Cone\Bazar\Support\Facades\Cart;
337331

338332
Cart::extend('custom', function ($app): CustomDriver {
339333
return new CustomDriver(
@@ -353,17 +347,17 @@ Taxes are stored on the `Item` and the `Shipping` models. Both implement the `Ta
353347
You may register taxes using the `Tax` facade. You can pass a number, a `Closure`, or a class (that implements the `Bazar\Contracts\Tax` interface) along with the name of the tax.
354348

355349
```php
356-
use Bazar\Support\Facades\Tax;
350+
use Cone\Bazar\Support\Facades\Tax;
357351

358352
// Fix tax
359353
Tax::register('fix-20', 20);
360354
```
361355

362356
```php
363357
// Custom closure tax
364-
use Bazar\Models\Shipping;
365-
use Bazar\Contracts\LineItem;
366-
use Bazar\Support\Facades\Tax;
358+
use Cone\Bazar\Models\Shipping;
359+
use Cone\Bazar\Contracts\LineItem;
360+
use Cone\Bazar\Support\Facades\Tax;
367361

368362
Tax::register('custom-percent', function (LineItem $model) {
369363
return $model->getPrice() * ($model instanceof Shipping ? 0.3 : 0.27);
@@ -372,10 +366,10 @@ Tax::register('custom-percent', function (LineItem $model) {
372366

373367
```php
374368
// Class tax
375-
use Bazar\Contracts\Tax as Contract;
376-
use Bazar\Contracts\LineItem;
377-
use Bazar\Models\Shipping;
378-
use Bazar\Support\Facades\Tax;
369+
use Cone\Bazar\Contracts\Tax as Contract;
370+
use Cone\Bazar\Contracts\LineItem;
371+
use Cone\Bazar\Models\Shipping;
372+
use Cone\Bazar\Support\Facades\Tax;
379373

380374
class CustomTax implements Contract
381375
{
@@ -395,7 +389,7 @@ Tax::register('complex-tax', new CustomTax);
395389
You may remove registered taxes using the `Tax` facade.
396390

397391
```php
398-
use Bazar\Support\Facades\Tax;
392+
use Cone\Bazar\Support\Facades\Tax;
399393

400394
Tax::remove('complex-tax');
401395
```
@@ -405,7 +399,7 @@ Tax::remove('complex-tax');
405399
You may disable tax calculation globally in some scenarios. To do so, call the `disable` method on the `Tax` facade.
406400

407401
```php
408-
use Bazar\Support\Facades\Tax;
402+
use Cone\Bazar\Support\Facades\Tax;
409403

410404
Tax::disable();
411405
```
@@ -423,15 +417,15 @@ Discounts are stored on the `Item` and the `Shipping` models. Both implement the
423417
You may register discounts using the `Discount` facade. You can pass a number, a `Closure`, or a class (that implements the `Bazar\Contracts\Discount` interface) along with the name of the discount.
424418

425419
```php
426-
use Bazar\Support\Facades\Discount;
420+
use Cone\Bazar\Support\Facades\Discount;
427421

428422
// Fix discount
429423
Discount::register('fix-20', 20);
430424
```
431425

432426
```php
433427
// Custom closure discount
434-
use Bazar\Support\Facades\Discount;
428+
use Cone\Bazar\Support\Facades\Discount;
435429

436430
Discount::register('custom-percent', function (Discountable $model) {
437431
return $model->getTotal() * 0.3;
@@ -440,9 +434,9 @@ Discount::register('custom-percent', function (Discountable $model) {
440434

441435
```php
442436
// Class discount
443-
use Bazar\Contracts\Discount as Contract;
444-
use Bazar\Contracts\Discountable;
445-
use Bazar\Support\Facades\Discount;
437+
use Cone\Bazar\Contracts\Discount as Contract;
438+
use Cone\Bazar\Contracts\Discountable;
439+
use Cone\Bazar\Support\Facades\Discount;
446440

447441
class CustomDiscount implements Contract
448442
{
@@ -462,7 +456,7 @@ Discount::register('complex-discount', new CustomDiscount);
462456
You may remove registered discounts using the `Discount` facade.
463457

464458
```php
465-
use Bazar\Support\Facades\Discount;
459+
use Cone\Bazar\Support\Facades\Discount;
466460

467461
Discount::remove('complex-discount');
468462
```
@@ -472,7 +466,7 @@ Discount::remove('complex-discount');
472466
You may disable discount calculation globally in some scenarios. To do so, call the `disable` method on the `Discount` facade.
473467

474468
```php
475-
use Bazar\Support\Facades\Discount;
469+
use Cone\Bazar\Support\Facades\Discount;
476470

477471
Discount::disable();
478472
```

core-concepts.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ After you created your customizable model, you can swap the container binding fo
3939
use App\Models\Product;
4040
use Cone\Bazar\Contracts\Models\Product as Contract;
4141

42-
public function register()
42+
public function register(): void
4343
{
4444
$this->app->bind(Contract::class, Product::class);
4545
}
@@ -53,6 +53,7 @@ Proxies are representing the classes that are currently bound to the container.
5353

5454
```php
5555
use Cone\Bazar\Models\Product;
56+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
5657

5758
// Available proxy methods
5859
Product::proxy();
@@ -63,7 +64,7 @@ Product::getProxiedContract();
6364
Product::proxy()->newQuery()->where(...);
6465

6566
// Dynamic usage of bound classes
66-
public function product()
67+
public function product(): BelongsTo
6768
{
6869
$this->belongsTo(Product::getProxiedClass());
6970
}

dashboard.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RootServiceProvider extends RootApplicationServiceProvider
2424
protected function widgets(): array
2525
{
2626
return [
27-
PostCount::make(),
27+
new PostCount,
2828
];
2929
}
3030
}

fields.md

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

36-
### Configuration
36+
## Configuration
3737

3838
### Value Resolution
3939

@@ -86,7 +86,7 @@ Number::make('Price')
8686
});
8787
```
8888

89-
## Authorization
89+
### Authorization
9090

9191
You may allow/disallow interaction with fields. To do so, you can call the `authorize` method on the field instance:
9292

@@ -526,6 +526,18 @@ Relation fields are representing Eloquent relation definitions on the resource m
526526

527527
#### Searchable & Sortable Columns
528528

529+
When using the `searchable` and `sortable` methods on the relation fields the target columns should be defined.
530+
531+
```php
532+
$field->searchable(columns: [
533+
'id', 'name',
534+
]);
535+
```
536+
537+
```php
538+
$field->sortable(column: 'name');
539+
```
540+
529541
#### Customizing the Query
530542

531543
You may customize the relatable model's query. This is possible defining global scopes per field type or locally on the field definition.
@@ -582,7 +594,7 @@ $field->aggregate('count', 'id');
582594
$field->aggregate('sum', 'tax');
583595
```
584596

585-
> The available aggregate functions: `count`, `min`, `max`, `sum`, `avg`.
597+
> The available aggregate functions: `count`, `min`, `max`, `sum` and `avg`.
586598
587599
#### Grouping
588600

@@ -602,6 +614,14 @@ $field->groupOptionsBy(static function (Model $model): string {
602614

603615
#### Subresources
604616

617+
When relation fields need more robust management you might convert it as a subresource. That means, instead of rendering a `<select>` on the resource form, the relation field gets its own CRUD interfaces as it would be a resource.
618+
619+
```php
620+
$field->asSubResource();
621+
```
622+
623+
Subresources appear on the parent resource models's show route.
624+
605625
### BelongsTo
606626

607627
The `BelongsTo` field is typically a handler for an existing `Illuminate\Database\Eloquent\Relations\BelongsTo` relation:
@@ -616,6 +636,25 @@ $field = BelongsTo::make(__('Author'), 'author');
616636

617637
The `BelongsToMany` field is typically a handler for a `Illuminate\Database\Eloquent\Relations\BelongsToMany` relation:
618638

639+
```php
640+
$field = BelongsToMany::make(__('Teams'), 'teams');
641+
```
642+
643+
When using as subresource, you may define editable pivot fields:
644+
645+
> Only existing models can be attached, creating relatable models from the subresource is not supported.
646+
647+
```php
648+
$field->withPivotFields(static function (Request $request): array {
649+
return [
650+
Select::make('Role', 'role')->options([
651+
'admin' => 'Admin',
652+
'member' => 'Member',
653+
]),
654+
];
655+
});
656+
```
657+
619658
### HasMany
620659

621660
The `HasMany` field is typically a handler for a `Illuminate\Database\Eloquent\Relations\HasMany` relation:

0 commit comments

Comments
 (0)