laravel backpack repeatable type not working in backpack version 4.1 - laravel

I want to clone same fields. SO, I am trying to using repeatable type but when I click on add button then no action is performed.
backpack version : 4.1
CRUD::addField([ // Extra Features
'name' => 'clergy_discription',
'label' => 'Extra Features',
'type' => 'repeatable',
'subfields' => [
[
'name' => 'feature',
'wrapper' => [
'class' => 'col-md-3',
],
],
[
'name' => 'quantity',
'type' => 'number',
'wrapper' => [
'class' => 'col-md-3',
],
],
],
]);

Related

broken column sequence backpack laravel

There was a column order issue. I finished making edits, after a few hours I returned to the project and saw that the columns of the table were mixed up, although before that everything worked correctly.
This is my setup method
public function setup()
{
/*
|--------------------------------------------------------------------------
| CrudPanel Basic Information
|--------------------------------------------------------------------------
*/
$this->crud->setModel('App\Models\Geozone');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/geozone');
/*
|--------------------------------------------------------------------------
| CrudPanel Configuration
|--------------------------------------------------------------------------
*/
$this->crud->allowAccess('show');
$this->crud->setActionsColumnPriority(10000);
$this->transIt();
$this->addColumnsT([
[
'name' => "polygons_json",
'visibleInTable' => false,
],
[
'name' => 'groups', // the method that defines the relationship in your Model
'type' => "select_multiple",
'entity' => 'groups', // the method that defines the relationship in your Model
'attribute' => "description", // foreign key attribute that is shown to user
'model' => "App\Models\GeozoneGroup", // foreign key model
//'visibleInTable' => false,
'number_columns' => 1,
],
[
'name' => "priority",
'visibleInTable' => false,
],
[
'name' => 'uz',
'type' => 'check',
],
[
'name' => 'frz',
'type' => 'check',
],
[
'name' => 'slz',
'type' => 'check',
],
[
'name' => 'ntz',
'type' => 'check',
]
]);
if(\Request::has('filter')) $this->crud->query = $this->crud->query->where(\Request::get('filter'), true);
if(\Request::has('deleted')){
$this->crud->addClause('onlyTrashed');
$this->crud->removeAllButtonsFromStack('line');
$this->crud->addButtonFromModelFunction('line', 'restore', 'restoreActionButton');
}
$this->addFieldsT([
[
'type' => "textarea",
'name' => 'polygons_json',
'attributes' => [
'readonly'=>'readonly',
],
],
]);
$this->addFieldsT([
[
'type' => "checklist",
'name' => 'groups', // the method that defines the relationship in your Model
'entity' => 'groups', // the method that defines the relationship in your Model
'attribute' => "description", // foreign key attribute that is shown to user
'model' => "App\Models\GeozoneGroup", // foreign key model
'pivot' => true,
'direction' => 'row'
],
]);
$this->addFieldsT([
[
'type' => "color_picker",
'name' => 'fill_color',
'attributes' => [
'pattern' => '^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$'
]
],
]);
$this->addFieldsT([
[
'type' => "color_picker",
'name' => 'stroke_color',
'attributes' => [
'pattern' => '^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$'
]
],
]);
$this->addFieldsT([
[
'name' => 'fill_opacity',
'attributes' => [
'pattern' => '\d{1}(\.\d{1,2})?'
]
],
]);
$this->addFieldsT([
[
'name' => 'stroke_opacity',
'attributes' => [
'pattern' => '\d{1}(\.\d{1,2})?'
]
],
]);
$this->crud->addFilter([ // select2_multiple filter
'type' => 'select2_multiple',
'name' => 'car_group',
'label'=> trans('columns.groups'),
], function() { // the options that show up in the select2
return \App\Models\GeozoneGroup::all()->pluck('description','id')->toArray();
}, function($values) {
$this->crud->addClause('join', 'geozone_to_group', 'id', 'geozone_to_group.geozone_id');
$this->crud->addClause('wherein', 'geozone_to_group.geozone_group_id', json_decode($values));
});
$this->crud->setCreateView('geozone_create');
$this->crud->setEditView('geozone_edit');
// add asterisk for fields that are required in GeozoneRequest
$this->crud->setRequiredFields(StoreRequest::class, 'create');
$this->crud->setRequiredFields(UpdateRequest::class, 'edit');
}
So the columns were arranged
[![enter image description here](https://i.stack.imgur.com/kQ1rP.jpg)](https://i.stack.imgur.com/kQ1rP.jpg)
I tried to change their location in the addColumns method, but it doesn't work. Although it works in other controllers.

How to add spinner to select list using ajax programmatically?

I want to add spinner to select list using ajax. I have tried below code for throbber but it's not working for select list.
$form['select choice'] = [
'#type' => 'select',
'#title' => t('Choice'),
'#attributes' => [
'class' => ['js-dop-chosen'],
],
'#options' => [
'---' => t('None'),
t('choice 1'),
t('choice 2'),
],
'#ajax' => [
'event' => 'change',
'wrapper' => 'form-wrapper',
'callback' => [$this, 'ajaxCallback'],
'progress' => [
'type' => 'throbber',
'message' => 'fetching content.....',
],
],
];

I have a problem with repeatable -> select2_from_array field in BackPack

I have this code:
Controller
$this->crud->addField(
[
'name' => 'schedule',
'label' => 'Schedule',
'type' => 'repeatable',
'fields' => [
[
'name' => 'day',
'label' => 'Day',
'type' => 'select_from_array',
'options' => Day::titles(),
'allows_null' => false,
],
[
'name' => 'range',
'label' => 'Range',
'type' => 'select2_from_array',
'options' => $this->getScheduleRange(),
'default' => $this->getDefaultScheduleRange(),
'allows_null' => false,
"allows_multiple" => true,
],
],
]
);
Model
protected $casts = [
'schedule' => 'array',
];
stored data in DB(schedule column):
[{"day": "1", "range[]": ["1:30:00", "2:00:00"]}]
But selected data not showing on the page when it is multi selected.
UPD:
After Pedro's recomandation it's not help me. In DB it's storing as:
[{"day": "1", "range[]": ["0", "1"]}]
viper.
when using multiple with default please use numeric keys like:
'options' => [0 => 'option 0', 1 => 'option 1'],
'default' => [0,1]
I think Backpack can do something here to improve multiple string keys like
'options' => ['option_0', 'option_1'],
'default' => ['option_0', 'option_1']
I will open an issue to discuss this in the package repository.
Thanks
Pedro

Laravel GraphQL UUID as ID does not work as expected

I'm using GraphQL in Laravel and I'm encountering this issue:
I've set id type to string but when I get my query through GraphQL, I get 553366 instead of 0553366c-6ebe-4340-8929-419ad46f4d15.
Here is my type definition:
public function fields(): array
{
return [
'id' => [
'type' => Type::string()
],
'name_en' => [
'type' => Type::string()
],
'name_fa' => [
'type' => Type::string()
],
'description' => [
'type' => Type::string()
],
'img_url' => [
'type' => Type::string()
],
'created_at' => [
'type' => Type::string()
],
'updated_at' => [
'type' => Type::string()
],
'SubBusinessFields' => [
'type' => Type::listOf(GraphQL::type('SubBusinessField'))
],
];
}
I've dd() the id and it was correct.
I've also tried id type instead of string but nothing changed.
How to fix this issue?
Just added this line to my Model and it got fixed!
public $incrementing = false;
It was weird that I couldn't find any similar problem anywhere else.

How to always show single validation message in ZF2 validators?

I have the following input:
private function addBirthdayElement()
{
return $this->add(
array(
'type' => 'DateSelect',
'name' => 'x_bdate',
'options' => [
'label' => 'astropay_birthday',
'label_attributes' => array(
'class' => 'astropay-label'
),
'create_empty_option' => true,
'render_delimiters' => false,
],
'attributes' => array(
'required' => true,
'class' => 'astropay-input',
)
)
);
}
It has the following filter:
public function addBirthdayFilter()
{
$time = new \DateTime('now');
$eighteenYearAgo = $time->modify(sprintf('-%d year', self::EIGHTEEN_YEARS))->format('Y-m-d');
$this->add(
[
'name' => 'x_bdate',
'required' => true,
'validators' => [
[
'name' => 'Between',
'break_chain_on_failure' => true,
'options' => [
'min' => 1900,
'max' => $eighteenYearAgo,
'messages' => [
Between::NOT_BETWEEN => 'astropay_invalid_birth_date_18',
Between::NOT_BETWEEN_STRICT => 'astropay_invalid_birth_date_18',
]
]
],
[
'name' => 'Date',
'break_chain_on_failure' => true,
'options' => [
'messages' => [
Date::INVALID => 'astropay_invalid_birth_date',
Date::FALSEFORMAT => 'astropay_invalid_birth_date',
Date::INVALID_DATE => 'astropay_invalid_birth_date',
],
]
],
],
]
);
return $this;
}
However, putting an empty date, I get the error message defined for:
Date::INVALID_DATE
But it's not the overridden one. The break_chain_on_failure works for the two validators I have defined, but the default Zend message is always there. For example I get this as an error in my form:
The input does not appear to be a valid date
astropay_invalid_birth_date_18
How can I display only the overidden error messages and 1 at a time?
You can use a message key in your validator configuration instead of a messages array to always show a single message per validator.
For example, replace this:
'options' => [
'messages' => [
Date::INVALID => 'astropay_invalid_birth_date',
Date::FALSEFORMAT => 'astropay_invalid_birth_date',
Date::INVALID_DATE => 'astropay_invalid_birth_date',
],
]
with this one:
'options' => [
'message' => 'Invalid birth date given!',
]

Resources