Skip to content

Instantly share code, notes, and snippets.

View bolechen's full-sized avatar
💭
I may be slow to respond.

Bole Chen bolechen

💭
I may be slow to respond.
View GitHub Profile
@guanguans
guanguans / InviteCode.php
Last active July 19, 2022 03:36
InviteCode.php
<?php
/**
* Class InviteCode
* 邀请码生成类
*
* ```
* $inviteCode = new InviteCode('123456789');
* var_dump($inviteCode->enCode(1)); // string(8) "00000002"
* var_dump($inviteCode->deCode("00000002")); // int(1)
@Oldenborg
Oldenborg / AssertJson.php
Last active October 2, 2023 22:50
Laravel test trait: assert JSON exact
<?php
namespace Tests\Traits;
use Illuminate\Testing\TestResponse;
use Illuminate\Support\Arr;
use PHPUnit\Framework\Assert as PHPUnit;
trait AssertJson
{
@torian257x
torian257x / app.blade.php
Last active April 26, 2021 07:29
multi build of laravel mix with performance improvement for tailwindcss "yarn hot" -> javascript as hot, tailwind as watch
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
@danielstgt
danielstgt / imagick3.4.4-PHP7.4-forge.sh
Last active April 19, 2024 11:33
Install ImageMagick / Imagick 3.4.4 on PHP 7.4 server (Laravel Forge)
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
apt-get install pkg-config libmagickwand-dev -y
cd /tmp
wget https://pecl.php.net/get/imagick-3.4.4.tgz
tar xvzf imagick-3.4.4.tgz
@Hanson
Hanson / LogServiceProvider.php
Created November 25, 2019 10:03
Laravel global model's log. You can rerord the admin's operation.
<?php
namespace App\Providers;
use App\Models\AdminLog;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;
class LogServiceProvider extends ServiceProvider
@roberto-butti
roberto-butti / main.yml
Last active December 16, 2023 23:43
GitHub Actions workflow for Laravel (automated test)
name: Laravel
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
laravel-tests:
@bolechen
bolechen / HasUuid.php
Last active October 12, 2020 10:58
Laravel Model Use Uuid
<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait HasUuid
{
/**
* Get the route key for the model.
@jakzal
jakzal / ExampleTest.php
Last active September 23, 2020 12:23
Set global variables with PHPUnit test method annotations
<?php
declare(strict_types=1);
namespace Zalas\Tests;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/**
@awesee
awesee / wechat_share.js
Created September 25, 2017 09:47
微信分享js
;(function ($) {
$(function () {
//用户自定义配置,可传入配置参数覆盖默认设置
wechatShare({
apiUrl: '/', //获取签名api
title: '分享标题', // 分享标题
desc: '分享描述', // 分享描述
link: window.location.href, // 分享链接
imgUrl: window.location.origin + '/public/images/wechat_share.png' // 分享图标
});
@vielhuber
vielhuber / Model.php
Last active July 11, 2023 16:51
custom relationship in eloquent / eager loading #laravel
<?php
public function foos() {
$relation = $this->hasMany('App\Bar');
return $relation; // default behaviour
// modify the query builder
$relation->where('foo','bar');
return $relation;