laravel 5.7

Databases and migrations:

(for both windows and linux based systems)

  1. Database(MySQL and phpmyadmin): The first and foremost requirement in order to connect the database with laravel application is to have a database eg. MySQL. Also, we need a GUI interface to easily interact with this database. For this purpose, phpmyadmin will work for us.
    • Firstly, login into phpmyadmin.
    • Create a database there having specific name, lets say “first”.
    • Open your laravel application in sublime on the other hand.
    • In .env file under your project directory, change the details of your database name and password for database MySQL.
    • Now, reload the phpmyadmin and you can check the database ‘first’ will be added there.
  2. migrations: Migrations in laravel are very important. They work the same way as a version control system. Whatever changes you will be making in the tables they can be directly with migrated to the server with the help of migrations. By default, two tables are already there having names ‘users’ and ‘password_resets’. In order to migrate follow :
    • php artisan migrate in command line.
    • Reload phpmyadmin and cross check the chnages.
    • In order to undo the changes that you just made run: php artisan migrate:rollback
    • Now, it is the turn to make a new table and migrate that table.
    • Run, php artisan make:migration name_of_table
    • This new table will be created under project/database/migrations. you can cross check.
    • Add the schema for this table in up() and down() function.
    • Migrate this using command php artisan migrate.
  3. eloquent models: We need an eloquent model with table that we just created.
       php artisan make:model name_of_model (note: the model name and the table name should be same)
  4. tinker : The tinker console allows you to interact with your Laravel application from the command line in an interactive shell. 
    • Php artisan tinker
    • App\name_of_model::all()