Laravel Migration Error - laravel-5.3

I cant seem to work out why I am getting this error on this migration file?
Error
[37;41m [Symfony\Component\Debug\Exception\FatalThrowableError] ←[39;49m
←[37;41m Call to a member function nullable() on null ←[39;49m
The date on the file is after the foreign id creation in the Customers table.This is laravel 5.3. How can I resolve this error?
public function up()
{
Schema::create('invoices', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->integer('customer_id')->unsigned();
$table->timestamps('date_from')->nullable();
$table->timestamps('date_to')->nullable();
$table->date('invoice_date')->nullable();
$table->date('due_at')->nullable();
$table->integer('total_charge')->nullable();
$table->integer('rate')->nullable();
$table->integer('total_hours')->nullable();
$table->string('status')->nullable();
$table->string('description', 255)->nullable();
$table->string('notes', 255)->nullable();
$table->string('invoice_ref')->nullable();
$table->foreign('customer_id')
->references('id')->on('customers')
->onDelete('cascade');
});
}

Use timestamp method in this two lines...
$table->timestamp('date_from')->nullable();
$table->timestamp('date_to')->nullable();
timestamps() not accepts any argument and creates two colums : created_at and updated_at
See Here

Remove these two lines from your code
$table->timestamp('date_from')->nullable();
$table->timestamp('date_to')->nullable();
And only include this line for the timpstamping:
$table->timestamps();

You replace it like this - remove the s from timestamp:
$table->timestamp('date_from');
$table->timestamps('date_day');

Related

Gosu system table query failing in Gunits

I have a Guidewire Gunit for a transformer in gosu which queries the system table to get a description for a result code which is working fine when run on the server but Gunit fails for the same.
I have tried the annotation #ServerTest for Gunit but that is failing as well.
The same code works fine in Gosu scratchpad.
PFA the code snippet as follows:
var resultCodes = Query.make(SystemTable).select().where(\elt -> elt.ResultCode == "AS01")
var description = ""
if(resultCodes != null && !resultCodes.isEmpty())
{
description = resultCodes.get(0).getFullDescription()
}
I'm getting the exception as follows :
java.lang.IllegalStateException: TableMetadataFactory cannot be used before it is started
Thanks,
Deepti
(Suggestion : )If your requirement is just to query based on some values.
Better dont use that .where() condition.
This is like SELECT * FROM <TABLE> and after getting all the data you are picking out your required result.
The best and the actual way is to use like
Query.make(TABLE_NAME).compare(TABLE_NAME#FIELD_NAME,Relop.Equals,"value_to_compare").select();
Query will be like
SELECT * FROM <TABLE_NAME> WHERE FIELD_NAME = FIELD_VALUE_TO_COMPARE;
While running Gunits, GW uses Shadow tables which will be basically empty.
Here if you are using OOTB entities, You can use Builder classes
or if you need to use some custom entities, use bundles to insert data first.
After inserting data into SystemTable (either using builder classes or bundles) run the below code.
var resultCodes = Query.make(SystemTable).compare(SystemTable#ResultCode ,Relop.Equals,"AS01").select()
foreach(result in resultCodes){
description = result.FullDescription
print("Output : "+description);
}
This happens when your RunLevel is set too low. Run levels below "NO_DAEMONS" will not load system tables. The default should be "NO_DAEMONS" so if you have an annotation on your test like this:
#RunLevel(gw.api.system.server.Runlevel.NONE)
either remove it or increase the level.
You can refactor your code like this:
uses gw.testharness.RunLevel
uses gw.api.database.Query
uses org.mockito.Mockito
uses gw.api.database.IQueryBeanResult
#RunLevel(NONE)
class StackOverflowTest {
function testDoQuery() {
var rs = Mockito.mock(IQueryBeanResult<SystemTable>)
var query = Mockito.mock(Query<SystemTable>)
Mockito.when(query.select()).thenReturn(rs)
var stackOverflow = Mockito.spy(new StackOverflow())
Mockito.doReturn(query).when(stackOverflow).getSystemTableQuery()
stackOverflow.doQuery()
Mockito.verify(stackOverflow, Mockito.times(1)).getSystemTableQuery()
Mockito.verify(query, Mockito.times(1)).select()
Mockito.verify(rs, Mockito.times(1)).iterator()
}
class StackOverflow {
function doQuery() {
var resultCodes = getSystemTableQuery().select().where(\elt -> elt.ResultCode == "AS01")
}
protected function getSystemTableQuery(): Query<SystemTable> {
return Query.make(SystemTable)
}
}
}

LocalDate with Property place holder Spring

I am working with Spring Boot and property placeholders. I have a property file with the value : date.A=24/07/17.
I have a class and I am using the #Value annotation:
#Value("${date.A}")
private LocalDate dateA;
But I am getting the runtime error when running gradle build integrationTest:
Caused by: java.time.format.DateTimeParseException: Text '24/07/17' could not be parsed: Invalid value for MonthOfYear (valid values 1 - 12): 24
at java.time.format.DateTimeFormatter.createError(DateTimeFormatter.java:1920)
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1855)
at java.time.LocalDate.parse(LocalDate.java:400)
I would need a closer look at the yml file to give the best answer..But here is my hunch-
The expected format is MM/dd/YY.
Can you please try changing the yml file to something like this
..
date
A=07/24/17
..
I think you need to write converter for that as follows:
public LocalDate convertToDateObject(String value) throws ConversionException {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
try {
return LocalDate.parse(value, formatter);
} catch (DateTimeParseException ex) {
return null;
}
}
The date should be specified in en_US locale, so you need to swap the month and day:
date.A=7/24/17

Dart encodeUriComponent Map.keys()

There is an example that I have seen in a number of places for encoding a Map as follows:
#import('dart:uri');
String encodeMap(Map data) {
return Strings.join(data.getKeys().map((k) {
return "${encodeUriComponent(k)}=${encodeUriComponent(data[k])}";
}), "&");
}
I'm running what appears to be the latest Dart editor (version 0.2.9_r 16323)
in the above example, for Dart M2, I believe that data.getKeys() has been changed to data.keys() which I have altered.
However, I get an error when running it in the Editor:
Exception: NoSuchMethodError : method not found: 'call'"
I have 2 questions:
I'm wondering if this above code should still work in M2 with the change indicated (Map.keys())?
I'm wondering if this above code does something different to: JSON.stringify(data);
Any other pointers are welcome.
TIA.
Two changes to do :
import syntax has changed.
getKeys() method became a getter called keys.
A working version :
import 'dart:uri';
String encodeMap(Map data) {
return Strings.join(data.keys.map((k) {
return "${encodeUriComponent(k)}=${encodeUriComponent(data[k])}";
}), "&");
}
The String generated by this encodeMap is quite different from the one generated by JSON.stringify as you can see in the bellow snippet :
main() {
final map = {"a":"b", "c":"d"};
assert(encodeMap(map) == "a=b&c=d");
assert(JSON.stringify(map) == '{"a":"b","c":"d"}');
}

multiple file upload symfony 2

How to use multiple files upload in symfony? I'm not really
sure how to do it 'the symfony way'. I read How to handle File Uploads with Doctrine, but how upload many files?
I try use collection field type and add setFiles method to object model
public function setFiles($files)
{
$this->files = $files;
foreach ($files as $file) {
$file->setObject($this);
}
}
but have exception (this always worked for normal model without any files)
Fatal error: Call to undefined method
Symfony\Component\HttpFoundation\File\UploadedFile::setObject()
please help me.
UPDATED:
I use for main object second form with file, and...
$files = $this->getRequest()->files->get('val_image');
foreach($files as $file){
$foto = new Foto;
$foto->setFile($file);
$foto->setPremises($premises->getPremises());
$this->getEm()->persist($foto);
}
it's works :)
Maybe this plugin can help you:
https://github.com/caoimhin/Symfony-jQuery-File-Upload/blob/master/Resources/public/README.md

LINQ-to-SQL does not retrieve the latest (updated) version stored in the database

When using a linqdatasource to update my sqlexpress database everything is displayed ok, but when I try retrieving the contents manually using:
public static IQueryable<MarkingScheme> listMarkingSchemes(string moduleID, string academicYear)
{
return
from m in feedbackDB.MarkingSchemes
where m.moduleID == moduleID && m.academicYear == academicYear
orderby m.schemeID descending
select m;
}
I get back a previous version of the data!! weirdly though, when I retrieve only specific parts of the same table, using:
public static IQueryable listNames(string moduleID, string academicYear)
{
return
from m in feedbackDB.MarkingSchemes
where m.moduleID == moduleID && m.academicYear == academicYear
orderby m.schemeID descending
select new { m.schemeID, m.assignmentName };
}
I get back the updated version!!!
Does anyone have any idea why this is happening, and how I can always get the latest version of the data when doing manual queries? I've tried setting the 'update check' option in the dataclasses.dbml file to either 'Always' and 'WhenChanged', but it didn't seem to work...
I finally got it to work, I had to manually set the Auto-Sync method to 'Always' for all affected columns in the datacontext!
Thanks again to #Josh for all his help, really appreciated!!

Resources