00:10 - Foreign Keys in Laravel 7 and below 01:35 - constrained() and nullable() 02:15 - Delete Parent: Restrict or Cascade? 04:10 - Change Order of Migrations 05:05 - What Migrations Have (not) Run? 05:40 - Timestamps with Default Value 06:23 - Customize Default Migration File 07:28 - Export Migrations into One SQL File 08:38 - Drop Multiple Columns 09:05 - Rollback or Refresh X Steps 09:57 - Auto-increment starting value 10:45 - Make Migration: Spaces vs Underscores
Another thing that may be helpfull - add unique number for migration class and name: php artisan make:migration users_fix_`date +%N` this will add nanoseconds value to migration name and class name making it abolutly unique. Work in unix systems only.
Thank you for this video. I know you have covered this elsewhere, but I can't recall - how do you add foreign keys to existing columns. For e.g. I have a table which is like user_id but I did not mention it was a foreign key at first. Is there a way to retroactively add that in?
You can create a new migration file and add $table->foreign('user_id')->references('id')->on('users'); But you need to make sure that current data does not violate that constrain, that there's no record with non-existing user_id.
Thanks you Sir for the awsome tips. I have a question on staps. In migrations sometimes we create for adding or removing colums or other, so at that time we dont need softDeletes is there any option to avoid softDeletes of other custom fields when we creating migration for columns?
Sir, your forgotten one of most typical Junior developer mistakes, they do any migration mutations in existing migration files, although they must do in seperate files.
If i want to change the column type, like string to datetimes from my database table, what is the best solution for this?
3 ปีที่แล้ว
Great content, 1 question, should I use key type based on the project size, like integer for small and big integer for larger project... or use biginteger everywhere like default. Is it worth trading some performance for faster coding
Dear Povilas! Do you have Laravel lessons series about scaling? For example, if you're doing complex social network (like TH-cam clone), how to scale it infinitely?
Hi, scaling is a very very individual thing, depending on the project and actual problems to solve: is it a DB issue? is it a Laravel code optimization issue? is it just adding more servers? etc. So it's very hard to create any kind of "definite" lessons on this topic. Maybe in the future I will come up with something.
sry to bother you my master teacher i have a question when i write the following command $table->foreignid('table_name')->constrained('table_name'); should i put it right after the foreign key table or in the primary key migration file if the first, how can i tell the laravel which primary key from which table to constrain ? laravel 8 version thanks in advanced .....
Can you help me, when i do the 'php artisan migrate' it doesn't migrate any file from database/migrations. And when i check at my database there are only Migrations table created in it. I tried the migrate:rollback but it show 'nothing to rollback', i tried the php artisan migrate again and again but it just showing 'nothing to migrate'
@@LaravelDaily I dont think so because i just created this new project and follow a tutorial from the beginning, and their migration works but mine dont.
Foreign constraints give me headaches 🤯 I collect data from the movie db api and EVERY key value can be missing... I had every record linked to a parent... Took me ages to get right. I had to remove ALL the constraints for seasons because many TV shows fails the queue job. At least I still have the TV constraint to remove everything belonging to that 😖
I am not fan of saving few milliseconds while not typing the underscore, but I'm a fan of not breaking my fingers, since for some reason I find it kinda difficult to type underscore with one hand :/
i hate timestamps.. because? there is a limit i found out that in mysql at least timestamp() will stop working from year 2038 or something... so maybe your system/app wont be around but w/e..
@@LaravelDaily ok thankyou, all i know withMax() is can't used on pivot table, i tired use user_id | project_id | rating User::withMax('projects', 'project_user.rating') it seems work, but the sql look weird ;( and also tired create a new model method user hasMany project relate to the pivot table, user_id | project_id | rating just don't know any better way to do this
00:10 - Foreign Keys in Laravel 7 and below
01:35 - constrained() and nullable()
02:15 - Delete Parent: Restrict or Cascade?
04:10 - Change Order of Migrations
05:05 - What Migrations Have (not) Run?
05:40 - Timestamps with Default Value
06:23 - Customize Default Migration File
07:28 - Export Migrations into One SQL File
08:38 - Drop Multiple Columns
09:05 - Rollback or Refresh X Steps
09:57 - Auto-increment starting value
10:45 - Make Migration: Spaces vs Underscores
You keep producing videos that are worthy of Oscar Award every time.
Man! You are the real deal
agree
Very clean and clear. What I love most about your videos is that that theirs no ambiguity at all. You're the best.👍
Thank you so much for contributing to the Laravel community! It's high quality content, well spoken, and I quite enjoy the topic as well. Farewell!
You are a gem in the Laravel community
Respect
😍 i realy love your tips , and hope to be able to pay some day for those courses , tyvm for all the hard work
You are the best teacher of Laravel, Thank you!
Thank you for sharing these tips! Your channel videos are simply amazing, simple, extremely useful, and inspiring.
Thanks, I have learned new tricks I didn't know about.
Another thing that may be helpfull - add unique number for migration class and name:
php artisan make:migration users_fix_`date +%N`
this will add nanoseconds value to migration name and class name making it abolutly unique.
Work in unix systems only.
Your videos are always worth watching. Thank you.
Your videos are so helpful and I'm learning so much from them, thanks a lot!
great content
also for migration names you can use:
php artisan make:migration AddFieldsToUsersTable
and it will add underscores
01:35 I learnt it the hard way. Edit: Thanks, I learned a lot!
Short tip and I know soft delete exist. Thanks!
You can also use camelCase on migrations and it will add _ and lowercase letter on each capital... I think that's even faster
*Nice tips I learned a few things, thanks!*
im happy that i use the same rename method to change the order of migration and i dont have evern 1 year of laravel experience
Very Informative 👏👏
Another usefull video , Thank You!
Incredible tutorials, thankyou so much.
Very useful, as always. Thank you very much!
Awesome teaching
Great content, tyvm.
Great content as always
Thank you for this video. I know you have covered this elsewhere, but I can't recall - how do you add foreign keys to existing columns. For e.g. I have a table which is like user_id but I did not mention it was a foreign key at first. Is there a way to retroactively add that in?
You can create a new migration file and add $table->foreign('user_id')->references('id')->on('users');
But you need to make sure that current data does not violate that constrain, that there's no record with non-existing user_id.
@@LaravelDaily So nullable cannot be applied in this way?
@@coolcha It can be applied, but if you already have values that don't have corresponding parent values, then nullable won't help.
@@LaravelDaily I see. Thank you for all your guidance and help.
Hello, what is the extension to be able to visualize in the code if it is a table or a column? thanks for your tutorials!
thank you so much your tutoreil it's very helpful
Thanks! Very useful tips!
you are the best
Thanks you Sir for the awsome tips. I have a question on staps. In migrations sometimes we create for adding or removing colums or other, so at that time we dont need softDeletes is there any option to avoid softDeletes of other custom fields when we creating migration for columns?
Sir, your forgotten one of most typical Junior developer mistakes, they do any migration mutations in existing migration files, although they must do in seperate files.
any video for this?
I would additionaly tell about "--table" and "--create" parameters in php "artisan make:migration". And maybe "php artisan make:model SomeModel -m"
More of these tips 👍
Love you so much sir ❤️❤️
Great sharing, thanks!
Which IDE are you using? And what’ extension?
Awesome, Very Useful!
really appropriate thanks
Can u make video on localization for both vuejs and blades files for multi language vue application which is also running with blades features .
This is how we use it: th-cam.com/video/pYtzXPrigKE/w-d-xo.html
If i want to change the column type, like string to datetimes from my database table, what is the best solution for this?
Great content, 1 question, should I use key type based on the project size, like integer for small and big integer for larger project... or use biginteger everywhere like default. Is it worth trading some performance for faster coding
Very helpful. Thanks
Man, i love you! serious
Dear Povilas!
Do you have Laravel lessons series about scaling?
For example, if you're doing complex social network (like TH-cam clone), how to scale it infinitely?
Hi, scaling is a very very individual thing, depending on the project and actual problems to solve: is it a DB issue? is it a Laravel code optimization issue? is it just adding more servers? etc. So it's very hard to create any kind of "definite" lessons on this topic. Maybe in the future I will come up with something.
Great video
Very helpful 👍😍
Thanks a lot It help me lot
dear sir, will you create a tutorial about Alibaba E-commerce website API integration ?
Thank you povilas
Thanks for another one 😊
I love your channel :)
Can you do a video updating Laravel 7 to 8
fine
This is excellent
When to use constrained() on a foreign key?🤔
Thanks you !
10:25 "Six million dollar man" mode
Thank Sir
sry to bother you my master teacher i have a question
when i write the following command
$table->foreignid('table_name')->constrained('table_name');
should i put it right after the foreign key table or in the primary key migration file
if the first, how can i tell the laravel which primary key from which table to constrain ?
laravel 8 version
thanks in advanced .....
Not sure I understand your question, please read the official documentation laravel.com/docs/8.x/migrations#foreign-key-constraints
Great tips ...
Is there a way to do a cascading soft delete?
Yes. Here's my article: blog.quickadminpanel.com/one-to-many-with-soft-deletes-deleting-parent-restrict-or-cascade/
Can you help me, when i do the 'php artisan migrate' it doesn't migrate any file from database/migrations. And when i check at my database there are only Migrations table created in it. I tried the migrate:rollback but it show 'nothing to rollback', i tried the php artisan migrate again and again but it just showing 'nothing to migrate'
Maybe you have put migrations innwrong folder? Or maybe you've called the classes/methods in nonstandard way so Laravel doesnt recognize them?
@@LaravelDaily I dont think so because i just created this new project and follow a tutorial from the beginning, and their migration works but mine dont.
Sorry, I can't debug it for you.
@@LaravelDailyIt's okay, Thanks for replying🙏🏾
Thanks
can we export migration and seeder into one sql file?
Yes, but not from Laravel, from your database client Export function.
Foreign constraints give me headaches 🤯
I collect data from the movie db api and EVERY key value can be missing...
I had every record linked to a parent... Took me ages to get right.
I had to remove ALL the constraints for seasons because many TV shows fails the queue job.
At least I still have the TV constraint to remove everything belonging to that 😖
wow, great!!!
Surpise there's no mention of $table->foreignIdFor($model)
It's not really widely used, even Taylor mentioned once on Twitter that he's not a fan of it, because model may change and then it breaks.
nice job new abonnée
Please turn on the subtitles
Can u make video laravel-websockets
I don't work with websockets currently, so can't make a video about it.
fantastic
I am not fan of saving few milliseconds while not typing the underscore, but I'm a fan of not breaking my fingers, since for some reason I find it kinda difficult to type underscore with one hand :/
will we lost data by rollback sir??
Yes if you delete the table/columns on rollback
@@LaravelDaily how to update migration files... like Add columns or modify datatypes without loss table data sir??
i hate timestamps.. because? there is a limit i found out that in mysql at least timestamp() will stop working from year 2038 or something... so maybe your system/app wont be around but w/e..
Great
How come that I get to know new things even though I'm from Symfony camp? O_o
can you make a video with use withMax() on pivot table price column?
Good suggestion, will do.
@@LaravelDaily ok thankyou, all i know withMax() is can't used on pivot table, i tired use
user_id | project_id | rating
User::withMax('projects', 'project_user.rating')
it seems work, but the sql look weird ;(
and also tired create a new model method user hasMany project relate to the pivot table,
user_id | project_id | rating
just don't know any better way to do this
Great video. Thanks!
Thank you!
Thanks
Great
Great