Skip to content

Instantly share code, notes, and snippets.

@putheakhem
Last active March 4, 2025 01:44
Show Gist options
  • Save putheakhem/29d94a78d0cd5edfcb1470f74d2bb2d4 to your computer and use it in GitHub Desktop.
Save putheakhem/29d94a78d0cd5edfcb1470f74d2bb2d4 to your computer and use it in GitHub Desktop.

Homework Lab: Building a Laravel CRUD Application

Objective

In this lab, you will create a Laravel application that includes the following:

  • A Model with an associated Migration
  • A Factory to generate dummy data
  • A View to display data
  • A Controller and Route to fetch and render data from the database

Tasks

1. Create the Model and Migration

  • Generate a Post model with a migration. php artisan make:model Post -m
  • Define the table structure in the migration file.
  • Run the migration to create the posts table.

2. Create a Factory for Dummy Data

  • Generate a factory for the Post model.
  • Define the structure for dummy data.
  • Call Seeder to generate sample data.

3. Create a View to Render Data ( Passing data from route)

  • Create a Blade template for displaying posts.
  • Use Blade syntax to loop through and display the posts.

4. Create a Controller and Route to Render Data ( After Next Session)

  • Generate a PostController.
  • Define an index method to fetch and pass posts to the view.
  • Create a route that maps to the index method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment