Material for this slide includes:
1. What is database
2. DBMS support for Laravel
3. Laravel migration
4. Laravel seeding
5. Laravel query builder
6. Laravel models
7. Laravel eloquent
3. 3
A database is an organized collection of structured
information, or data, typically stored electronically in a
computer system. A database is usually controlled by a
database management system (DBMS)
5. Laravel makes interacting with databases
extremely simple across a variety of database
backends using either raw SQL, the fluent query
builder, and the Eloquent ORM.
5
6. The database configuration for your application is located
at config/database.php.
In this file you may define all of your database
connections, as well as specify which connection should
be used by default.6
7. 7
Laravel has a pretty simple way to define database
config, All configuration that you should stay private and
should not share goes into the .env file of your laravel
project.
8. Migrations are like version control for your database, allowing
your team to modify and share the application's database schema.
Migrations are typically paired with Laravel's schema builder to
build your application's database schema.
8
9. To create a migration, use the make:migration Artisan
command:
The new migration will be placed in your
database/migrations directory. Each migration file name
contains a timestamp, which allows Laravel to determine
the order of the migrations.
9
10. 10
Laravel includes a simple method of seeding
your database with test data using seed classes.
All seed classes are stored in the
database/seeders directory.
11. To generate a seeder, execute the make:seeder
Artisan command. All seeders generated by the
framework will be placed in the
database/seeders directory:
A seeder class only contains one method by
default: run. This method is called when the
db:seed Artisan command is executed. Within
the run method, you may insert data into your
database however you wish
11
12. Laravel's database query builder provides a convenient,
fluent interface to creating and running database
queries. It can be used to perform most database
operations in your application and works on all
supported database systems.
12
13. You may use the table method on the DB facade to begin a query.
The table method returns a fluent query builder instance for the
given table, allowing you to chain more constraints onto the
query and then finally get the results using the get method:
13
14. 14
The Model corresponds to the letter ‘M’ in the MVC framework. The
motive of Models in any Model view controller framework web
application is to manage business logic. A Model is nothing but a
class in the Laravel framework. This class is responsible to
interact with underlying database tables.
15. Models typically live in the appModels directory, but you
are free to place them anywhere that can be auto-loaded
according to your composer.json file. All Eloquent
models extend IlluminateDatabaseEloquentModel
class.
The easiest way to create a model instance is using the
make:model Artisan command:
15
16. 16
The Eloquent ORM included with Laravel
provides a beautiful, simple ActiveRecord
implementation for working with your database.
Each database table has a corresponding
"Model" which is used to interact with that table.
17. We can work in Eloquent with database
efficiently using an ActiveMethod
implementation.
It is an architectural pattern where the model
created in the Model-View-Controller (MVC)
structure corresponds to a table in the
database.
The advantage is for models to perform
common database operations without coding
lengthy SQL queries.17
18. Andi Nurkholis, S.Kom., M.Kom.
September 28, 2020November 09, 2020
Study Program of Information Systems
Faculty of Engineering and Computer Science
SY. 2020-2021