How to cast value in Laravel 9 model before insertion to DB? - casting

I tried this:
protected $casts = [
'population' => 'integer',
'created' => 'datetime',
'edited' => 'datetime',
];
But get an Illuminate\Database\QueryException:
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: 'unknown' for column 'population' at row 1 ...

Related

Multiple Date Form Element in Drupal 9

I am trying to add a multiple date field (unlimited cardinality) in my custom module configuration form.
$form['holidayForm']['holidays'] = [
'#type' => 'date',
'#multiple' => TRUE,
'#title' => $this->t('Holidays'),
'#default_value' => $config->get('holidayForm.holidays'),
];
As you can see, I have added the #multiple property but I still get a single field
Is there a different property that I needed to add.

Gravity forms repeater with upload file error

I'm building a form with a repeater and a file upload inside. When I submit the form, the input file filed always give me the error: There was an error while uploading the file. Error code: 1
Add
Here's my code:
$uploadfiles = GF_Fields::create( array(
'type' => 'fileupload',
'id' => 1006, // The Field ID must be unique on the form
'formId' => $form['id'],
'multipleFiles' => false,
'allowedExtensions' => 'gif,jpg,jpeg,png,txt,rtf,pdf,doc,docx,odt,ppt,pptx,odp,xls,xlsx,ods,xml',
'description' => '<br>Relevant documents: our transport way bill, probill, photos, etc.<br>Files must be less than 2 MB.<br>Allowed extensions: gif jpg jpeg png txt rtf pdf doc docx odt ppt pptx odp xls xlsx ods xml.',
'label' => __('Please attach any relevant document', 'srx'),
'pageNumber' => 1, // Ensure this is correct
));
// Create a repeater for the team members and add the name and email fields as the fields to display inside the repeater.
$team = GF_Fields::create( array(
'type' => 'repeater',
'description' => '',
'id' => 1000, // The Field ID must be unique on the form
'formId' => $form['id'],
'label' => __('Products', 'srx'),
'addButtonText' => __('Add product', 'srx'),
'removeButtonText' => __('Remove product', 'srx'),
'maxItems' => 100, // Optional
'pageNumber' => 1, // Ensure this is correct
'fields' => array( $reference, $quantity, $product, $lista, $uploadfiles ), // Add the fields here.
) );
Even tho the field is not required, it gives me the error anyways.
Another question I have is about the use of multipleFiles = true. This doesn't work at all. Any idea why ?
Thank you so much !
The Repeater API does not currently support File Upload fields. Here's a full list of known limitations:
https://docs.gravityforms.com/repeater-fields/#limitations
If you need repeating file uploads, check out Gravity Forms Nested Forms:
https://gravitywiz.com/documentation/gravity-forms-nested-forms/

Conversion from realurl to routeEnhancers in TYPO3 9... Adapt LookUpTables with additional ValueMaps or how to define the "zero-value-segment"?

I am upgrading a project about training courses and my URL-segments are like:
/category/course/location.html
Got it running with the following configuration:
routeEnhancers:
PageTypeSuffix:
type: PageType
default: '.html'
map:
'.html': 0
CoursePlugin:
type: Extbase
limitToPages:
- 1
- 15
- 17
- 18
extension: Course
plugin: Catlist
namespace: course_catlist
routes:
- routePath: '/{category_title}/{course_title}/{location_title}'
_controller: 'Category::list'
_arguments: {category_title: 'category', course_title: 'course', location_title: 'location'}
defaultController: 'Category::list'
aspects:
category_title:
type: PersistedAliasMapper
tableName: tx_course_domain_model_category
routeFieldName: 'slug'
course_title:
type: PersistedAliasMapper
tableName: tx_course_domain_model_course
routeFieldName: 'slug'
location_title:
type: StaticValueMapper
map:
alle-standorte: 0
hamburg: 1
berlin: 2
The problem is now: It's only working if there are values for all 3 parameters set! But for example there could be a segment like
/language-courses/all-courses/berlin.html
The course-parameter is empty, so all "language-courses" in "berlin" are shown in a list.
In realurl it is possible to combine a lookUpTable with a valueMap!
array(
'GETvar' => 'tx_course_catlist[course]',
'valueMap' => array(
'all-courses' => "",
),
'lookUpTable' => array(
'table' => 'tx_course_domain_model_course',
'id_field' => 'uid',
'alias_field' => 'title',
'addWhereClause' => ' AND deleted=0 ',
'useUniqueCache' => 1,
'useUniqueCache_conf' => array(
'strtolower' => 1,
'spaceCharacter' => '-',
),
),
)
How can I adapt this in TYPO3 9? Any experience or ideas? How can I map an empty-value for a segment of a PersistedAliasMapper?
Found a solution:
Create a record with an uid=0 in the database. Call the path-segment-field for example like "all-courses".
This has an unpleasant side effect that the record appears in the TYPO3 backend and if you want to edit it, you get an error message that the UID must not be 0. So just do it via PHPmyadmin...
And you have to make sure that the value passed to course is not NULL but "0" when building the URL.

Why is my Auth.User given me null as value ? What is the relationship between sessions and PhpUnit ?

2) App\Test\TestCase\Controller\UsersControllerTest::testLogin
Session content for "Auth.User" differs.
null does not match expected type "array".
This is the code that I have
function testLogin()
{
$this->enableCsrfToken();
$this->enableSecurityToken();
$this->post('/users/login', [
'username' => 'username#test.test',
'password' => 'password'
]);
$expected = [
'username' => 'username#test.test',
'password' => 'password'
];
$this->assertSession($expected, 'Auth.User');
$expected = [
'controller' => 'Index',
'action' => 'index'
];
$this->assertRedirect($expected);
}
I am using cakephp3.0 and IntegrationTestCase. It seems to me like I can't login ? Why is there a null value for Auth.User ? What is the relationship between PhpUnit and sessions ? I don't get this.
What am I doing wrong ?
Isn't the 'Auth.User' what is written in the session ? I am a beginner with testing.

Dynamodb query error - Query key condition not supported

I am trying to query my dynamodb table to get feed_guid and status_id = 1. But it returns Query key condition not supported error.
Please find my table schema and query.
$result =$dynamodbClient->createTable(array(
'TableName' => 'feed',
'AttributeDefinitions' => array(
array('AttributeName' => 'user_id', 'AttributeType' => 'S'),
array('AttributeName' => 'feed_guid', 'AttributeType' => 'S'),
array('AttributeName' => 'status_id', 'AttributeType' => 'N'),
),
'KeySchema' => array(
array('AttributeName' => 'feed_guid', 'KeyType' => 'HASH'),
),
'GlobalSecondaryIndexes' => array(
array(
'IndexName' => 'StatusIndex',
'ProvisionedThroughput' => array (
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5
),
'KeySchema' => array(
array(
'AttributeName' => 'status_id',
'KeyType' => 'HASH'
),
),
'Projection' => array(
'ProjectionType' => 'ALL'
)
),
array(
'IndexName' => 'UserIdIndex',
'ProvisionedThroughput' => array (
'ReadCapacityUnits' => 5,
'WriteCapacityUnits' => 5
),
'KeySchema' => array(
array(
'AttributeName' => 'user_id',
'KeyType' => 'HASH'
),
),
'Projection' => array(
'ProjectionType' => 'ALL'
)
)
),
'ProvisionedThroughput' => array(
'ReadCapacityUnits' => 10,
'WriteCapacityUnits' => 20
)
));
Following is my query to update that table.
$result = $dynamodbClient->query(array(
'TableName' => 'feed',
'KeyConditionExpression' => 'feed_guid = :v_fid AND status_id = :v_sid ',
'ExpressionAttributeValues' => array(
':v_fid' => array('S' => '71a27f0547cd5456d9ee7c181b6cb2f8'),
':v_sid' => array('N' => 1)
),
'ConsistentRead' => false
));
As mentioned, the attribute included in "KeyConditionExpression" should be your hash key only, matching your base table schema (in this case 'feed_guid'). If you want to query on both 'feed_guid' and 'status_id', you need to create the table with hash and range key and specify 'status_id' as your range key.
Global secondary indexes are completely separate from the base table, so in this case you can query the indexes separately (use 'status_id' in key condition when querying StatusIndex and use 'user_id' in key condition when querying UserIdIndex).
Please find more details on querying global secondary indexes here
Another option would be to use a FilterExpression in addition to the KeyConditionExpression. As Daniela mentioned KeyConditionExpression should contain only columns in the hash key. But any un-indexed columns can be included in the FilterExpression.
You need to have both hash_key (Partition Key) and range_key (Sort Key) provided in the KeyConditionExpression. hash_key must be exact match (=), but the range_key can use other operators like 'begins_with'