-
Notifications
You must be signed in to change notification settings - Fork 0
Laravel: Creating CRUD workflow
Once project is set up (e.g. .env file is connected with the database, web server is actively serving), using the MVC functionality of Laravel:
-
Build a model with a migration file using
php artisan make:model [name] -m
-
Configure the model's migration file that was made (specifically the
up
function), located in/database/migrations/yyyy_mm_dd_ssssss_create_[name]_table.php
... refer to https://laravel.com/docs/11.x/migrations#creating-columns for the Blueprint column types -
Migrate the model into the database using
php artisan migrate
-
Create the controller using
php artisan make:controller [name]
(e.g. if model is Patient, do PatientController)... controllers will be stored in/app/http/controllers
-
Create the view... can use Bootstrap (https://getbootstrap.com/) but need to have CDN
<link
and<script
in the<head>
... views will go in/resources/views/
-
Will need a different view for each CRUD action: create/add, read/view, update, delete.
-
Create the input items... under
<input
the fieldname=
matches up with the model's field name. -
Add web routes for the application under
web.php
. Add isRoute::post
; Delete isRoute::get
. Edit is aRoute::get
and aRoute:post
. -
Compile all the business/assignment/functionality logic to the controller in
/app/http/controllers
-
The operations are all complete- but for a full listing/index, will need to iterate the models stored in the database and display to a table.
For detailed code samples, see: https://medium.com/@ldudaraliyanage/building-your-first-laravel-10-crud-application-in-under-30-minutes-28a7f1979304