nguyenduy4994 / nearby-test

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Requirement

Check out Laravel Requirements & Installations.

Must meet minimum requirement:

  • PHP >= 7.3
  • Composer
  • NPM
  • MySQL 8+

System design

Database design

Database design

Database detail

People table:

People table:

Points table:

Points table:

Installation

Clone from this repository

git clone git@github.com:nguyenduy4994/comflysoft-test.git

Install by following command

cd comflysoft-test
composer install
yarn install

Copy new environment file

cp .env.example .env

Generate new key

php artisan key:generate

Migration & seed

# For new install
php artisan migrate --seed

# If you want to drop all table and migrate new
php artisan migrate:refresh --seed

Generate IDE helper file

php artisan clear-compiled
php artisan ide-helper:generate

Run npm to build style

yarn dev
// or watching change files
yarn watch

Run test

php artisan test

Coding style & Fixing

Applied from the style set that Laravel is using from Styleci. Simply use command to fix basic style

composer fix-style

You can use php-cs-fixer implement to your IDE to automatic fix style when saving, commit.

Follow PSR standards.

Package usage

Structure & Guide

Model

Usage

All models are in App\Models

Model example

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SystemLog extends Model
{
    /**
     * The attributes that aren't mass assignable.
     *
     * @var array
     */
    protected $guarded = [];

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;
}

Constant

All constant are defined in namespace App\Constants in folder app\Constants

Example:

<?php

namespace App\Constants;

class Error
{
    const PEOPLE_STORE_FAIL = 1;
    const POINT_STORE_FAIL = 2;
}

Service & Facade

Introduction

I apply Facade in services to help more convenient in writing code. Please check the Facades document

All service in namespace App\Services in folder app/Services. All service's facades in namespace App\Facades.

How to create services

Step 1: Define a Service class in folder app/Services

<?php

namespace App\Services;

class PeopleService extends Service
{
}

Step 2: Define a Facade class in folder app/Facades with

<?php

namespace App\Facades;

use App\Services\PeopleService as ServicesPeopleService;
use Illuminate\Support\Facades\Facade;

class PeopleService extends Facade
{
    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return ServicesPeopleService::class;
    }
}

How to use service

<?php

namespace App\Http\Controllers;

use App\Facades\PointService;

class DashboardController extends Controller
{
    public function index()
    {
        // ...
        $points = PointService::getWithPaginate(),

        // ...
    }
}

Routing

All route in folder routes:

  • web.php: route for all

Form request

All form request are defined in app\Http\Requests with name Store or Update depending on what type of the request.

Logging & Exception

Logging

All exceptions are logged as Laravel document.

Exception

I implement custom Exception in folder App\Exceptions. When store fail, throw StoreFailException.

Logging

Follow guide from: https://laravel.com/docs/8.x/logging

Best practice

Please check https://github.com/alexeymezenin/laravel-best-practices

About


Languages

Language:PHP 64.1%Language:Blade 35.4%Language:Shell 0.5%