6
0
Fork 0
jiqu-library-server/app/Admin/Forms/OrderPackage.php

74 lines
1.6 KiB
PHP

<?php
namespace App\Admin\Forms;
use App\Models\Order;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;
class OrderPackage extends Form implements LazyRenderable
{
use LazyWidget;
/**
* 权限判断,如不需要可以删除此方法
*
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.product_spus.add_sku');
}
/**
* Handle the form request.
*
* @param array $input
*
* @return mixed
*/
public function handle(array $input)
{
dd($input);
return $this->response()
->success(__('admin.update_succeeded'))
->refresh();
}
/**
* Build a form here.
*/
public function form()
{
$orderId = $this->payload['order_id'] ?? 0;
$order = Order::findOrFail($orderId);
$this->hidden('order_id');
$this->text('shipping_company');
$this->text('shipping_number');
$this->hasMany('packages', function (Form $form) use ($order) {
$form->select('order_product_id')->options($order->products->pluck('name', 'id'));
$form->number('quantity')->min(0);
});
$this->disableResetButton();
}
/**
* The data of the form.
*
* @return array
*/
public function default()
{
return [
// 'name' => 'John Doe',
// 'email' => 'John.Doe@gmail.com',
];
}
}