Skip to content

Instantly share code, notes, and snippets.

View cuonghuynh's full-sized avatar
🏠
Working from home

Cuong Huynh cuonghuynh

🏠
Working from home
View GitHub Profile
namespace App\Support;
abstract class AbstractValidator
{
protected $errors;
/**
* handle checking data is valid
* @return boolean
<?php
namespace App\Validators;
use App\Support\AbstractValidator;
class CreateItemDataValidator extends AbstractValidator
{
/**
* handle checking data is valid
<?php
namespace App\Validators;
class ValidationException extends \Exception
{
public function __construct($message, $errors, $code = 0, \Exception $previous = null)
{
$this->errors = $errros;
@cuonghuynh
cuonghuynh / SystemUtil.php
Last active November 22, 2016 03:19
Function helper to get max file upload size in Bytes
<?php
namespace App\Infrastructure\Utilities;
class SystemUtil
{
public static function maxFileUploadSize()
{
//select maximum upload size
$maxUpload = self::getBytes(ini_get('upload_max_filesize'));
@cuonghuynh
cuonghuynh / gulp.js
Last active November 22, 2016 03:18
Add method to export fonts from bootstrap
const elixir = require('laravel-elixir');
require('laravel-elixir-vue-2');
/*
|--------------------------------------------------------------------------
| Elixir Asset Management
|--------------------------------------------------------------------------
|
| Elixir provides a clean, fluent API for defining some basic Gulp tasks
@cuonghuynh
cuonghuynh / CorsMiddleware.php
Last active November 22, 2016 03:17
Setup CORS for your api
//app\Http\Middleware\Cors.php
<?php
namespace App\Http\Middleware;
use Closure;
class CorsMiddleware
{
@cuonghuynh
cuonghuynh / LogRequestMiddleware.php
Last active November 22, 2016 03:16
Request Logging
<?php
namespace App\Http\Middleware;
use Closure;
use Auth;
use App\Models\Log;
use App\Services\RequestLogger;
class LogRequestMiddleware
@cuonghuynh
cuonghuynh / CustomModel.php
Last active November 22, 2016 03:16
Time ago in words
<?php
protected $appends = [
'created_at_ago',
'updated_at_ago'
];
public function getCreatedAtAgoAttribute() {
return $this->created_at->diffForHumans();
}
@cuonghuynh
cuonghuynh / RolesTrait.php
Last active November 22, 2016 03:14
Handling Roles
<?php
namespace App\Traits\User;
use App\Models\Role;
use App\Models\Permission;
use Illuminate\Database\Eloquent\ModelNotFoundException;
trait Roles {
public function roles()
@cuonghuynh
cuonghuynh / BaseRequest.php
Created November 22, 2016 03:15
Turning off Validation Redirects
<?php
namespace App\Http\Requests;
use Illuminate\Http\JsonResponse;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exception\HttpResponseException;
abstract class BaseRequest extends FormRequest
{