Giter Site home page Giter Site logo

basic-crud's Introduction

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.2
  • Composer 2.0.8
  • MySQL 8.0.23
  • 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

  • Update the database configuration according to your local environment

  • Create a new database for testing

  • Run the following commands

    php artisan key:generate --env=testing
    npm install && npm run build
    ./vendor/bin/pest --parallel

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

    Update the DB_HOST environment variable to value mysql (should be same as service name of database server)

  3. Install dependencies

    docker run --rm \
        -u "$(id -u):$(id -g)" \
        -v "$(pwd):/var/www/html" \
        -w /var/www/html \
        laravelsail/php82-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

  • Update the DB_HOST environment variable to value mysql (should be same as service name of database server)

  • Create a new database for testing

    ./vendor/bin/sail mysql
    
    > create database <testing_database_name>
  • 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 ./vendor/bin/pest --parallel

Give Feedback ๐Ÿ’ฌ

Give your feedback on @MrPunyapal

Contribute ๐Ÿค

Contribute if you have any ideas to improve this project.

basic-crud's People

Contributors

mrpunyapal avatar hosmelq avatar imrjat avatar dcblogdev avatar jigar-dhulla avatar vishal2931 avatar ludoguenet avatar shailesh-matariya avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.