Skip to content

Example of crud operations best practices for beginner to advanced

Notifications You must be signed in to change notification settings

MrPunyapal/basic-crud

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel CRUD Operations Best Practices Example Beginner to Advanced

Tests

Getting Started 🚀

These instructions will guide you through setting up the project on your local machine for development and testing.

Prerequisites

You need to have installed the following software:

  • PHP 8.3
  • Composer 2.0.8
  • Node 20.10.0

Installing

Follow these steps to set up a development environment:

  1. Clone the repository

    git clone https://github.com/mr-punyapal/basic-crud.git
  2. Install dependencies

    composer install
    npm install
  3. Duplicate the .env.example file and rename it to .env

    cp .env.example .env
  4. Generate the application key

    php artisan key:generate
  5. Run migration and seed

    php artisan migrate --seed
  6. Run the application

    npm run dev
    php artisan serve

How to Test the Application 🧪

  • Copy .env.testing.example to .env.testing

  • Run the following commands

    php artisan key:generate --env=testing
    npm install && npm run build
    # Lint the code using Pint
    composer lint
    composer test:lint
    
    # Refactor the code using Rector
    composer refactor
    composer test:refactor
    
    # Run PHPStan
    composer test:types
    
    # Run type coverage
    composer test:type-coverage
    
    # Run the test suite
    composer test:unit
    
    # Run all the tests
    composer test

Check composer.json for more details on scripts.

Installing with Sail

Laravel Sail is helpful when your local environment doesn't match with project requirements like different PHP versions. Only requirement is Docker to work with this project. For more details on Laravel Sail click here.

Follow these steps to set up a development environment using Laravel Sail:

  1. Clone the repository

    git clone https://github.com/mr-punyapal/basic-crud.git
  2. Duplicate the .env.example file and rename it to .env

    cp .env.example .env
  3. Install dependencies

    docker run --rm \
        -u "$(id -u):$(id -g)" \
        -v "$(pwd):/var/www/html" \
        -w /var/www/html \
        laravelsail/php83-composer:latest \
        composer install --ignore-platform-reqs
    ./vendor/bin/sail run --rm laravel.test npm install
  4. Run the application

    ./vendor/bin/sail up -d
    ./vendor/bin/sail npm run dev
  5. Generate the application key

    ./vendor/bin/sail artisan key:generate
  6. Run migration and seed

    ./vendor/bin/sail artisan migrate --seed

How to Test the Application with Sail 🧪

  • Copy .env.testing.example to .env.testing

  • Run the following commands

    ./vendor/bin/sail artisan key:generate --env=testing
    ./vendor/bin/sail npm install && ./vendor/bin/sail npm run build
    ./vendor/bin/sail run --rm laravel.test composer test

Give Feedback 💬

Give your feedback on @MrPunyapal

Contribute 🤝

Contribute if you have any ideas to improve this project.

About

Example of crud operations best practices for beginner to advanced

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published