group by和union,Laravel分页
摘要:$res3 = DB::table('users') ->join('user_folow_boutiques', 'user_folow_boutiques.user_id', '=', 'users.id') ->join('boutique', 'boutique.id', '=', 'use
阅读全文
laravel groupBy 分页
摘要:$model=DB::table('tablebname') ->where(function($query) use ($res){ $query->where('xx','xx'); }) ->selectRaw("area,from_unixtime(created_time,'%Y-%m-%
阅读全文
laravel whereHas sum & addSelect sum
摘要:$users = User::select('id', 'username', 'coins', 'cut') ->when(request()->has('agent_tip_sum'), function ($q) { $q->whereHas('agentBoughts', function
阅读全文
LaravelORM 中的 withSum , withAvg, withMax,withMin 的实现
摘要:Orm::withCount(['relation as relation_sum' =>function($query){ $query->select(DB::raw("sum(amount) as relationsum")); }])
阅读全文
无限极分类
摘要:class CategoryController extends Controller { public function index() { $rootCats = Category::where('parent_id', null)->get(); return $this->tree($rootCats); } priv...
阅读全文
laravel order by
摘要:orderBy(\DB::Raw('case when avatar_id = 0 then 0 else 1 end')) Doctor::join('users', 'doctors.user_id', '=', 'users.id') ->with('user') ->withCount('services', 'notebooks') ->orderByDesc('notebooks_co
阅读全文
laravel 编辑后跳转回分页
摘要:进入edit页面时将分页地址保存在session中,更新后跳转该地址
阅读全文
前端token刷新并发处理
摘要:添加中间件,处理多个前端来的请求时,如果token需要刷新,先查看缓存,如果没有就在redis中做个标志位进行短期缓存,其他的请求发现缓存中的token,就不再刷新token了。这样就避免了重复刷新token的问题。 中间件代码
阅读全文
api token
摘要:1. implement the registered() method in our RegisterController 2. User Generate Token 3. Just like the registration endpoint, we can edit the LoginCon
阅读全文
How to fix Error: laravel.log could not be opened?
摘要:Never set a directory to 777. you should change directory ownership. so set your current user that you are logged in with as owner and the webserver u
阅读全文
Cors 跨域访问API
摘要:server()['HTTP_ORIGIN'] ?? false; if ($origin && in_array($origin, $domains)) { header('Access-control-Allow-Origin: ' . $origin); header('Access-control-Allow-Headers...
阅读全文
多文件上传
摘要:$files = $request->allFiles(); foreach ($files as $file) { $fileName = uniqid() . ‘.’ . $file->getClientOriginalExtension(); $file->move(‘temp_test’, $fileName); }
阅读全文
Update Request
摘要:public function update(UpdateAppointmentRequest $request) { try { $data = array_filter($request->only(['user_id','status','note'])); $appointment = $this->appointment->findOrFai...
阅读全文
protected $appends in Laravel
摘要:protected $appends = ['icon']; public function getIconAttribute(){ return Gravatar::src($this->email, 100).'&r=g&d=mm'; }
阅读全文
throw exception
摘要:Throw new CustomerException('Customer message'); // App\Exceptions\Handler.php public function render($request, Exception $e) { // 没有权限访问 if ($e instanceof ForbiddenExcep...
阅读全文
laravel DB事物
摘要:public function store(Request $request, $id) { $externalAccount = ExternalAccounts::find($id); DB::beginTransaction(); try { $externalAccount->fund_nu
阅读全文