How can I define the length of increments in laravel migrations? - laravel

Hi I have a column that it is increments but I do not know how I can define the length because I did it like this:
$table->increments('section_id', 100);
It did not work at all, it added just 10...
So I wonder how can I fix it? Thanks

Related

only show events who are greater than or equal laravel

Im working in a project where I display different events in my view. The goal for now is to only show events that are upcoming, so it doesn't show events that are older than today.
The users of my page can create an event and set a sertain date for it.
The data is stored into my db like this:
$table->string('datum');
In the view it return it like this:
06.03.2019
My controller to return the data looks like this:
$date = date('d.m.Y');
$evententries = Event::where('datum', '>=', $date)->orderBy('datum', 'asc')->take(3)->get();
but it's somehow not working..
Anyone got any Ideas of how to fix this and what my issue is here?
btw, I'm using laravel 5.7.
Thank you :)
Hmm you are doing it on wrong way from begin...
First: why you are using string to store date value? there is much better options to store date within database...
Second: you are using date format which cannot be compared on that way (using < > =)
when you are comparing strings ie 08.03.2019 will be always smaller than 10.01.2016 because 1 > 0... so if you are comparing dates use:
db format for storing dates
for comparing use format yyyy-mm-dd because on that way even simple string comparison will give you correct result...

Laravel schema column

I'm trying to make numeric column in my table but I'm not sure which option would be the best fit for my need
logic
numbers start from 4 figure up e.g. 1000
no ending limitation can goes up like: 999999999999999999999999999999999999999999
increased incrementally e.g. last number was 1000, next will be 1001 (not random numbers)
Question
Laravel provided several option that can do my job but I need help to know which is the best for my purpose
bigIncrements
bigInteger
unsignedBigInteger
ALSO there is one option ->autoIncrement() should I add that too?

How can I remove unique column laravel 5

How can I dropUnique the column a_b from z table?
If it would be just column a, we can do this:
$table->dropUnique('z_a_unique');
I've tried:
$table->dropUnique('z_a_b_unique');
But obviously it didn't work.
Thanks for your help in advance!
dropUnqiue() will drop index, not the column. You need to use dropColumn() after dropUnique():
$table->dropColumn('a_b');
Actually, the answer is in the question, sorry guys, it works like this:
$table->dropUnique('z_a_b_unique');
And solved my problem

Using pluck with maximum

Is it possible to chain options when using maximum?
I have a PhoneStats class and I want to pull the name from a few columns who have the maximum value in the table. For example if I run
PhoneStat.maximum('calls')
I get the value I expect but I would like to get maximum value as well as the id of the user in that record. Is it possible to use pluck or collect for something like this?
Thanks spickermann
Thanks. Below got me exactly what I needed.
PhoneStat.order('calls DESC').pluck(:name).first
You have to write this a bit more detailed:
PhoneStat.order('calls DESC').first

Get maximum value with Zend_Db_Table

Ive got a Zend_Db_Table
Now I want to get the maximum available value of a field.
Is there a way to get the MAX(number) value or do I need to use basic SQL?
Thanks!
Use
new Zend_Db_Expr('MAX(number)')
as one of the fields in the Zend_Db_Table_Select.

Resources