Skip to content

Instantly share code, notes, and snippets.

View blood72's full-sized avatar

Kim Dong-Hyeon blood72

  • @marketboro 마켓보로
  • South Korea
  • 12:11 (UTC +09:00)
View GitHub Profile
@blood72
blood72 / IsEncrypted.php
Created February 19, 2020 05:57
IsEncrypted.php
<?php
use Illuminate\Support\Facades\Validator;
Validator::extend('encrypted', function ($attribute, $value, $parameters, $validator) {
try {
return decrypt($value);
} catch (\Illuminate\Contracts\Encryption\DecryptException $exception) {
return false;
}
@blood72
blood72 / isSoftDeleting.php
Last active March 17, 2020 03:41
Determine if the model implements soft deletes and does soft delete.
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Model;
trait isSoftDeleting
{
/**
* Determine if the model implements soft deletes and does soft deleting.
@blood72
blood72 / Character.php
Last active April 23, 2020 07:45
Return character(s) for each position(s) to string
<?php
use Illumniate\Support\Str;
if (! Str::hasMacro('character')) {
Str::macro('character', static function ($value, $positions, $glue = '') {
if (! is_array($positions)) {
$positions = [$positions];
}
<?php
if (! function_exists('random_float')) {
/**
* Generates random float number.
*
* @param int|float $min
* @param int|float $max
* @param int $digit
* @return float|int
<?php
namespace App\Concerns;
use App\Casts\HashableKey;
trait CanRouteKeyHashing
{
/** @var bool */
protected $hashedKey = false;
@blood72
blood72 / FakerGenerator.php
Last active May 21, 2020 16:14
Add randomBody method in Faker\Generator class
<?php
namespace App\Packages;
use Faker\Generator;
/**
* @method string randomBody($maxDepth = 4, $maxWidth = 4)
*/
class FakerGenerator extends Generator
@blood72
blood72 / Permission404Middleware.php
Created June 29, 2020 07:11
404 middleware version of spatie/laravel-permission.
<?php
namespace App\Http\Middleware;
use Closure;
use Spatie\Permission\Middlewares\PermissionMiddleware as Middleware;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Permission404Middleware extends Middleware
{
@blood72
blood72 / PreferredLanguage.php
Last active July 17, 2020 15:38
Laravel middleware that changes to user preferred language (without route prefix).
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class PreferredLanguage
{
@blood72
blood72 / 2020_07_24_create_attachments_table.php
Created August 1, 2020 03:22
Attachment model (personal use)
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateAttachmentsTable extends Migration
{
/**
* Run the migrations.
@blood72
blood72 / RestrictFromReferer.php
Last active January 21, 2021 13:56
(Laravel) Allow request only if Referrer header is base same domain
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
class RestrictFromReferer
{