我的结d里有一个田地
$this->crud->addField([
'name' => 'transaction_type',
'label' => 'Transaction Type',
'type' => 'select2',
'entity' => 'transactionType',
'attribute' => 'name',
'model' => 'App\Models\TransactionType',
'attributes' => [
'required' => true,
],
]);
$this->crud->addField([
'name' => 'developer_id',
'label' => 'Developer',
'type' => 'select2',
'entity' => 'developer',
'attribute' => 'name',
'model' => 'App\Models\Developer',
]);
我想使developer_id所需的属性为true,因为默认情况下为false。我知道如何通过下面的代码将其设为虚假
$this->crud->modifyField('developer_id',['attributes' => [
'required' => true,
]]);
现在的问题是,在developer_id
中选择一个选项后,如何使'required' => true
到transaction_type
?
到目前为止,我所要做的就是将'data_source' => url("admin/api/devrequirement")'
放在transaction_type的addfield中。所以看起来像这样
$this->crud->addField([
'name' => 'transaction_type',
'label' => 'Transaction Type',
'type' => 'select2',
'entity' => 'transactionType',
'attribute' => 'name',
'data_source' => url("admin/api/devrequirement"), //i added it here
'model' => 'App\Models\TransactionType',
'attributes' => [
'required' => true,
],
]);
,然后将一条路线放入我的自定义路线中:
Route::get('/api/devrequirement', 'SaleCrudController@setDevRequirement');
该函数内部是:
public function setDevRequirement(Request $request)
{
$form = collect($request->input('form'))->pluck('value', 'name');
$transaction_type = $form['transaction_type'];
if($transaction_type == 3) //if transaction type is equal to a specific value then required attribute of developer_id should be true
{
$this->crud->modifyField('developer_id',['attributes' => [
'required' => true,
]]);
}
}
但是它什么也没做。它没有在我的开发人员字段上添加红色星号,也没有要求验证。我在laravel背包以及如何使用其操作ajax方面遇到了困难。
答案 0 :(得分:0)
没关系,我只是创建自定义字段并在其中放置一些js操作