Skip to content

Laravel: Creating CRUD workflow

Ibi Keller edited this page Mar 24, 2024 · 3 revisions

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:

  1. Build a model with a migration file using php artisan make:model [name] -m

  2. 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

  3. Migrate the model into the database using php artisan migrate

  4. 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

  5. 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/

  6. Will need a different view for each CRUD action: create/add, read/view, update, delete.

  7. Create the input items... under <input the field name= matches up with the model's field name.

  8. Add web routes for the application under web.php. Add is Route::post; Delete is Route::get. Edit is a Route::get and a Route:post.

  9. Compile all the business/assignment/functionality logic to the controller in /app/http/controllers

  10. 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

Clone this wiki locally