Check out Laravel Requirements & Installations.
Must meet minimum requirement:
- PHP >= 7.3
- Composer
- NPM
- MySQL 8+
People table:
Points table:
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
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.
- barryvdh/laravel-debugbar use for debuging.
- barryvdh/laravel-ide-helper use for generating file which helps IDE auto complete.
- matt-allan/laravel-code-style The tools checks the input PHP source code and reports any deviations from the coding convention.
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;
}
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;
}
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
.
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;
}
}
<?php
namespace App\Http\Controllers;
use App\Facades\PointService;
class DashboardController extends Controller
{
public function index()
{
// ...
$points = PointService::getWithPaginate(),
// ...
}
}
All route in folder routes
:
web.php
: route for all
All form request are defined in app\Http\Requests
with name Store
or Update
depending on what type of the request.
All exceptions are logged as Laravel document.
I implement custom Exception in folder App\Exceptions
. When store fail, throw StoreFailException.
Follow guide from: https://laravel.com/docs/8.x/logging
Please check https://github.com/alexeymezenin/laravel-best-practices