Laravel DB insert([]) only insert first record of array - postgresql

I have this simple seeder class but for some reason is only inserting the first element from the array and the command is not returning any error.
Im using Laravel 5.8 and postgres as DB engine.
<?php
use Illuminate\Support\Carbon;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class PermissionsTableSeeder extends Seeder
{
public function run()
{
DB::table('permissions')->insert([
'id' => 1,
'name' => 'list_users',
'display_name' => 'List users',
'description' => 'Can list all users',
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
],
[
'id' => 2,
'name' => 'show_user',
'display_name' => 'Show single user',
'description' => 'Can show single user details',
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
]);
}
}
Result:

You need to provide an array of arrays as the first argument:
DB::table('permissions')->insert([
[
'id' => 1,
'name' => 'list_users',
'display_name' => 'List users',
'description' => 'Can list all users',
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
],
[
'id' => 2,
'name' => 'show_user',
'display_name' => 'Show single user',
'description' => 'Can show single user details',
'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
'updated_at' => Carbon::now()->format('Y-m-d H:i:s')
]
]);

Related

Disabling the past dates

I want to disable the past dates from the laravel-backpack component date-range-picker.
`$this->crud->addField([
'name' => ['event_start_date', 'event_end_date'],
'type' => 'date_range',
'label' => "Start Date",
'wrapperAttributes'=>['class'=>'form-group col-md-6'],
'default' => [date("Y-m-d"), date("Y-m-d")],
'date_range_options' => [
'todayBtn' => 'linked',
'timePicker' => true,
'format' => 'YYYY-MM-DD'
],
'allows_null' => true,
]);`
How can I do that?
$this->crud->addField([
'name' => ['event_start_date', 'event_end_date'],
'type' => 'date_range',
'label' => "Start Date",
'wrapperAttributes'=>['class'=>'form-group col-md-6'],
//'default' => [date("Y-m-d"), date("Y-m-d")],
'date_range_options' => [
'todayBtn' => 'linked',
// options sent to daterangepicker.js
//'timePicker' => true,
'startDate' => date("Y-m-d"),
'endDate' => date("Y-m-d"),
'minDate'=> date("Y-m-d"),
'locale' => ['format' => 'YYYY-MM-DD']
],
'allows_null' => true,
]);

cakephp3.1: Cannot limit the fields loaded in association

I execute the following query:
$sites = $this->Sites->find('all')
->select(['id', 'name'])
->contain([
'Users' => function ($q) {
return $q->select(['id', 'owner_id', 'firstname', 'lastname']);
},
])
->matching('Users', function ($q) use($owner_id)
{
return $q->where([
'Users.owner_id' => $owner_id
]);
})
->all();
So I insert a select() statement in Users association to restrict the retrieved fields to id, owner_id, firstname and lastname but it returns the following result:
'items' => [
(int) 0 => object(App\Model\Entity\Site) {
'id' => (int) 7,
'name' => 'the site',
'orders' => [],
'users' => [
(int) 0 => object(App\Model\Entity\User) {
'id' => (int) 49,
'owner_id' => (int) 42,
'firstname' => 'Ed',
'lastname' => 'Gavin',
'username' => 'EdG',
'password' => '$2y$10$jHN7/mLwkh7O.aOHVmAeK.PnY9IrT/tTpcKlH25Il0yLtveE6.Onu',
'email' => 'ed.gavin#yopmail.com',
'phone' => '',
'role' => 'owner',
'active' => (int) 1,
'token' => '8cf196e6b45e972fbfec11eb7b80748d',
'origin' => '',
'_joinData' => object(App\Model\Entity\SitesUser) {
Can you tell me why the select() is not respected for Users?

CakePHP3.1: disable options in a select input

I want to disable options in a select input so I tried:
echo $this->Form->select("status",
[
'options' => $status,
'value' => $order->status,
'label' => false,
'disabled' => [1, 2]
]);
But it doesn't generate any disabled statement in html code.
What's my mistake?
the correct way to set the attributes to the select's options is to pass an array like this
$options = [
[ 'text' => 'option 1', 'value' => 'value 1', 'disabled' => true],
[ 'text' => 'option 2', 'value' => 'value 2', 'disabled' => true],
[ 'text' => 'option 3', 'value' => 'value 3'],
[ 'text' => 'option 4', 'value' => 'value 4']
];
echo $this->Form->select(
'status',
$options,
['value' => $order->status, 'label' => false]
);
You should use input function of FormHelper and set type = "select"
.My sample(only selectable Three)
$status = [1 => 'One', 2 => 'Two', 3 => 'Three'];
echo $this->Form->input("status",
[
'type' => 'select',
'options' => $status,
'label' => false,
'disabled' => [1, 2]
]
);

ZF 2.4 File Validator Required False Doesn't Work

Today I updated to ZF 2.4 to use float validator but unfortunately i realized that my file upload form field gives unexpected error messages.
Here is my form object
$this->add([
'name' => 'profileimage',
'type' => '\Zend\Form\Element\File',
'attributes' => [
'id' => 'profileimage',
'class' => 'styled',
],
]
);
And Here is my validator
$inputFilter->add([
'name' => 'profileimage',
'required' => false,
'allow_empty' => true,
'priority' => 300,
'filters' => [
['name' => 'StripTags'],
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => '\Zend\Validator\File\IsImage',
],
[
'name' => '\Zend\Validator\File\UploadFile',
],
[
'name' => '\Zend\Validator\File\ImageSize',
'options' => [
'minWidth' => 300,
'minHeight' => 300,
]
],
[
'name' => '\Zend\Validator\File\Size',
'options' => [
'max' => '20MB',
]
],
]
]);
As you see the image upload field is not required and may be empty. But in my form I get these errors:
array (size=1)
'profileimage' =>
array (size=4)
'fileIsImageNotReadable' => string 'File is not readable or does not exist' (length=38)
'fileUploadFileErrorNoFile' => string 'File was not uploaded' (length=21)
'fileImageSizeNotReadable' => string 'File is not readable or does not exist' (length=38)
'fileSizeNotFound' => string 'File is not readable or does not exist' (length=38)
How can I handle this issue? I need to this field to be optional.
change your filter
$inputFilter->add([
'name' => 'profileimage',
'type' => '\Zend\InputFilter\FileInput',
'required' => false,
'allow_empty' => true,
'priority' => 300,
'filters' => [
['name' => 'StripTags'],
['name' => 'StringTrim'],
],
'validators' => [
[
'name' => '\Zend\Validator\File\IsImage',
],
[
'name' => '\Zend\Validator\File\UploadFile',
],
[
'name' => '\Zend\Validator\File\ImageSize',
'options' => [
'minWidth' => 300,
'minHeight' => 300,
]
],
[
'name' => '\Zend\Validator\File\Size',
'options' => [
'max' => '20MB',
]
],
]
]);
read about it here: http://framework.zend.com/manual/current/en/modules/zend.input-filter.file-input.html

zf2 form collection don't show element description

When the collection element is rendered , description element does not appear.
ZF2 seems to ignore the description option in the form collection.
Form
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'value',
'options' => array(
'label' => 'Please choose value',
'count' => 1,
'should_create_template' => true,
'target_element' => new ValueFieldset($objectManager)
)
));
Form Fieldset: ValueFieldset
$this->add(array(
'name' => 'name',
'type' => 'Zend\Form\Element\Text',
'options' => array(
'label' => 'Values',
'label_attributes' => array(
'class' => 'form-label'
),
'description' => 'X',
'multiple' => true,
),
)
);
View
echo $this->formCollection($values);