+ 2
Laravel
Who knows how to manipulate a database using Laravel 8
3 odpowiedzi
+ 2
I didn't use Laravel 8 yet but I used Laravel 5.6 along with its models and database migrations. I created several migrations for a project that died a couple years ago. From what I can see, Laravel 8 has the same database features with only minor improvements.
Laravel's migrations are how you should create and migrate your database schema.
Laravel 8 migrations are described at:
https://laravel.com/docs/8.x/migrations
Some tutorials might add tables directly to the database instead of using Laravel migrations but they're skipping a critical step. If your project needs even a small schema change after it is in production, you'll need a data migration. Waiting until you're in production to familiarize yourself with migrations would be a mistake. They're not hard but procrastinating with that learning process can lead to more mistakes when you're rushing to fix something in production than if you've already warmed up to it throughout the early development phase. Making migration mistakes early in development is easier to manage than doing it with production data on a live site.
Laravel's Eloquent ORM is how you interact with the database. Eloquent would be used mostly in your controllers but relationships can be defined in your models.
This is one of those tutorials skipping migrations to add a database table but it shows a little about the use of Eloquent in a simple web app:
https://www.youtube.com/watch?v=VjqS9LPPmIA
Official Laravel 8 Eloquent documentation is at:
https://laravel.com/docs/8.x/eloquent
Also, check out Laravel's database seeding features. Database seeding is where you'd add and maintain some data from code in your project. It can be useful for data that you hard-code references to. For example, if you have a countries database table with countries that user never changes, seeding them would be helpful.
More details on seeding are at:
https://laravel.com/docs/8.x/seeding
0
Josh Greig
I've actually read the Laravel 8 docs but I can't find out what I'm looking for 😩
I'm building a web app that requires multiple databases and I only how to work with one database with multiple tables
It's a school management system app and it's giving me tough time to link the databases together
I was then thinking if I can use one database, then I'll have some other tables inside a particular table still in the same database.
Do you think this will actually work?
0
If you have a single Laravel application and want it to directly talk with more than one database, it looks like you just configure multiple database connections in the .env and reference them from models and controllers.
This tutorial shows it:
https://www.youtube.com/watch?v=MQsDt5Hyals
I had only 1 MySQL database in my last Laravel project but that looks straightforward.
I didn't quickly see how Laravel's migrations would be applied to a specific database when there are many connections but it sounds like you don't care so much about that.
I would generally avoid having more than 1 database but that sounds out of your control. Maybe your databases existed before and interact with other software that needs to continue working.