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.
Related
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',
],
],
],
]);
Controller (field definition):
$this->crud->addField([
'name' => 'precios',
'type' => "relationship",
'pivotSelect' => [
'ajax' => true,
'inline_create' => [ 'entity' => 'precio' ],
'data_source' => backpack_url('presupuesto/fetch/precio'),
'minimum_input_length' => 0,
'wrapper' => [
'class' => 'col-md-3 order-2'
],
'attributes' => [
'required' => 'required',
],
'dependencies' => ['categoria_precio_id']
],
'subfields' => [
[
'name' => 'categoria_precio_id',
'type' => 'relationship',
'label' => 'CategorÃa',
'wrapper' => [
'class' => 'form-group col-md-2 order-1',
],
'dependencies' => ['tipo'],
'ajax' => true,
'data_source' => backpack_url('presupuesto/fetch/categoria-precio'),
'minimum_input_length' => 0
],
[
'name' => 'costo',
'type' => 'text',
'label' => 'Costo Unitario',
'wrapper' => [
'class' => 'form-group col-md-1 order-3',
],
],
[
'name' => 'cantidad',
'type' => 'text',
'wrapper' => [
'class' => 'form-group col-md-1 order-4',
],
],
[
'name' => 'duracion',
'type' => 'text',
'wrapper' => [
'class' => 'form-group col-md-2 order-5',
]
],
[
'name' => 'costo_final',
'type' => 'text',
'label' => 'Costo',
'wrapper' => [
'class' => 'form-group col-md-1 order-6 costo_final',
],
'attributes' => array('readonly' => 'readonly', 'disabled' => 'disabled')
],
],
'tab' => "Precios",
'force_delete' => true]);
My Form capture
When I tried to select an option that I selected previously it does not allow me. For example, in the image "animación 2d" (ID:82).
First I have in my table "precio_presupuesto"
precio_id (PK)
presupuesto_id (PK)
costo
...
created_at
updated_at
And I change that for:
id (PK)
precio_id (FK)
presupuest_id (FK)
costo
...
created_at
updated_at
In my model I had:
public function precios()
{
return $this->belongsToMany(\App\Models\Precio::class)->withPivot('costo', 'cantidad', 'duracion', 'categoria_precio_id', 'costo_final')->withTimestamps();
}
And I change that for:
public function precios()
{
return $this->belongsToMany(\App\Models\Precio::class,'precio_presupuesto', 'presupuesto_id','precio_id', 'id')->withPivot('costo', 'cantidad', 'duracion', 'categoria_precio_id', 'costo_final')->withTimestamps();
}
I'm new to Laravel and Backpack, but I think my definition is fine, I just don't know how to tell Backpack to allow adding two elements with repeated "price_id" and "presupuesto_id", this because there will be cases where you can change the "cantidad" field or the "costo" field for the same combination (precio_id, presupuesto_id).
In other words I just want the "Select2" subfields not to disable previously selected options.
My model
I have tried changing the definition of my models again. Create a class for the pivot table following the documentation and example of:
doc
example
Presupuesto Model
class Presupuesto extends Model implements Auditable{
public function precio_presupuesto(){
return $this->hasMany(PrecioPresupuesto::class, 'presupuesto_id');
}
public function precios(){
return $this->belongsToMany(\App\Models\Precio::class)->using(\App\Models\PrecioPresupuesto::class)->
withPivot('costo', 'cantidad', 'duracion', 'categoria_precio_id', 'costo_final')->withTimestamps();
}
}
Precio Model:
class Precio extends Model{
public function precio_presupuesto()
{
return $this->hasMany(PrecioPresupuesto::class, 'precio_id');
}
public function presupuestos()
{
// return $this->belongsToMany(\App\Models\Presupuesto::class);
return $this->belongsToMany(\App\Models\Presupuesto::class)->using(\App\Models\PrecioPresupuesto::class)->
withPivot('costo', 'cantidad', 'duracion', 'categoria_precio_id', 'costo_final')->withTimestamps();
}}
Pivot Model:
class PrecioPresupuesto extends Pivot{
public function presupuesto(){
return $this->belongsTo(Presupuesto::class, 'presupuesto_id');
}
public function precio(){
return $this->belongsTo(Precio::class, 'precio_id');
}}
Does Backpack allow me to save several pairs of elements like in the image pivot table precio_presupuesto? what is what I need? because it currently does not allow me.
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.
I am trying to validate recursive data which could have any number of levels e.g.
[
'name' => 'test',
'children' => [
[
'name' => 'test2'
],
[
'name' => 'test3',
'children' => [
'name' => 'test4'
]
],
[
'name' => 'test5',
'children' => [
'name' => 'test6'
'children' => [
'name' => 'test7'
]
]
]
]
]
In this example I would require the following rules to ensure that a name is specified at each level:
$rules = [
'name' => ['required'],
'children' => ['array'],
'children.*.name' => ['required'],
'children.*.children' => ['array'],
'children.*.children.*.name' => ['required'],
'children.*.children.*.children' => ['array'],
'children.*.children.*.children.*.name' => ['required'],
]
How could I dynamically generate the validation rules based on the data coming in?
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!',
]