Skip to content

Instantly share code, notes, and snippets.

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

guanguans guanguans

🏠
Working from home
View GitHub Profile
@guanguans
guanguans / export.md
Last active May 18, 2022 03:35
#excel ajax 导出

Excel ajax 导出

Export

<?php

namespace App\Exports;

use App\Models\Product;
@guanguans
guanguans / Laravel-Container.md
Created March 2, 2022 19:15
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@guanguans
guanguans / diffIds.php
Last active February 15, 2022 10:05
#diffIds #verify
<?php
$diffIds = \Illuminate\Support\Str::of($inputStrIds = '1,2,5, ')
->trim()->trim(',')->trim()
->explode(',')
->filter(function ($value){
return filled($value);
})
->map(function ($item){
return trim($item);
@guanguans
guanguans / PriorityQueue.php
Created January 21, 2022 03:29
#PriorityQueue
<?php
class PriorityQueue
{
private $queue = [];
public function enqueue($item, $priority)
{
$this->queue[] = [$item, $priority];
$this->sort();
@guanguans
guanguans / go.md
Created December 31, 2021 08:26
go.md
This file is part of the guanguans/translator.
(c) $originalComment.match("Copyright \(c\) (\d+)", 1, "-", "$today.year")$today.year. guanguans <ityaozm@gmail.com>
This source file is subject to the MIT license that is bundled.
find src/ -type f -name '*.php' -print0 | xargs -0 -L1 -P4 -- php -l -f;

列表 GET

  • 列表 GET book/list 或者 book/index 或者 books
  • 详情 GET book/show/{id} 或者 book/detail/{id}
  • 保存 POST book/store
  • 更新 POST book/update/{id}
  • 保存/更新 POST book/save/{id?}
  • 删除 GET book/destroy/{id} 或者 book/delete/{id}
@guanguans
guanguans / string.md
Last active September 10, 2021 04:52
PHP 字符串中解析函数写法

写法

${!${''} = 你的代码块}

var_dump(${!${''} = implode('、', ['apple', 'banana'])});

示例

$fruits = implode('', ['apple', 'banana']);
@guanguans
guanguans / memoization.php
Last active July 6, 2021 08:45
memoization.php
<?php
if (! function_exists('memoization')) {
/**
* 记忆录
*
* @param callable $callback
* @param ...$parameter
*
* @return mixed