Laravel Eloquent ORM

AccessibleJasper avatar
AccessibleJasper
·
·
Download

Start Quiz

Study Flashcards

10 Questions

What is the purpose of the php artisan model:show Flight command?

To inspect the attributes and relationships of a model

The make:model command generates a model in the app/Controllers directory.

False

What is the shortcut to generate a model, migration, factory, seeder, policy, controller, and form requests?

php artisan make:model Flight --all or php artisan make:model Flight -a

The php artisan make:model Flight --controller command generates a model and a _______________________ class.

FlightController

Match the following Artisan commands with their purposes:

php artisan make:model Flight -crR = Generate a model, FlightController resource class, and form request classes php artisan make:model Flight -p = Generate a pivot model php artisan make:model Flight -mfsc = Generate a model and a migration, factory, seeder, and controller php artisan model:show Flight = Inspect the attributes and relationships of a model

What is the purpose of Eloquent in Laravel?

To interact with the database in an enjoyable way

The Laravel Bootcamp is a tutorial on building a Laravel application without using Eloquent.

False

What is the default directory where Eloquent models live?

app\Models

You can use the ______________ command to generate a new model.

make:model

Match the following options with their purpose in generating a model:

--migration = Generate a database migration --factory = Generate a factory class --seed = Generate a seeder class -m = Generate a migration

Study Notes

Laravel Eloquent

  • Eloquent is an object-relational mapper (ORM) that makes it enjoyable to interact with your database.
  • Each database table has a corresponding "Model" that is used to interact with that table.
  • Eloquent models allow you to retrieve, insert, update, and delete records from the table.

Configuring the Database

  • Before using Eloquent, configure a database connection in your application's config/database.php configuration file.
  • For more information on configuring your database, check out the database configuration documentation.

Laravel Bootcamp

  • Laravel Bootcamp walks you through building your first Laravel application using Eloquent.
  • It's a great way to get a tour of everything that Laravel and Eloquent have to offer.

Generating Model Classes

  • Models typically live in the app\Models directory and extend the Illuminate\Database\Eloquent\Model class.
  • Use the make:model Artisan command to generate a new model.
  • You can generate various other types of classes when generating a model, such as factories, seeders, policies, controllers, and form requests.

Model Options

  • Use the --migration or -m option to generate a database migration when generating the model.
  • Use the --factory or -f option to generate a factory class.
  • Use the --seed or -s option to generate a seeder class.
  • Use the --controller or -c option to generate a controller class.
  • Use the --resource or -R option to generate a controller resource class.
  • Use the --requests option to generate form request classes.
  • Use the --policy option to generate a policy class.
  • Use the --all option to generate a model, migration, factory, seeder, policy, controller, and form requests.

Inspecting Models

  • Use the model:show Artisan command to get a convenient overview of all the model's attributes and relations.

Eloquent Model Conventions

  • Models generated by the make:model command will be placed in the app/Models directory.
  • Eloquent models follow certain conventions, such as model naming and directory structure.

Learn about Eloquent, Laravel's object-relational mapper, and how to interact with your database. Configure a database connection and perform CRUD operations.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser