Laravel
type total subtotal 1 10 0 1 0 20 2 100 0 2 0 200 LaravelでUNION ALLしたこういう結果表を集計したいときは以下のように書く。 DB::table(DB::raw('(' . $subQuery->toSql() .') AS s1')) ->mergeBindings($subQuery) ->selectRaw( 'SUM(s1.total) + SUM…
起きたこと Dockerコンテナ上のComposerでパッケージを追加しようとした時にCannot allocate memoryエラーが出た。 [root@8b736af411ab www]# composer require --dev squizlabs/php_codesniffer mmap() failed: [12] Cannot allocate memory mmap() failed:…
use Illuminate\Support\Facades\Hash; ... $user = User::where(['id' => 1])->firstOrFail(); // passwordはHash::make()で作成 $beforeHash = $request['beforeHash']; if (Hash::check($beforeHash, $user->password)) { echo("一致しました!"); } else…
withで指定した要素に無名関数を渡す order by Order::with(['order_detail' => function ($query) { $query->orderByDesc('created_at'); }])->get(); select * from `order_details` where `order_details`.`id` in (1) order by `created_at` desc where …
Laravelでhaving句を使って集計を行うとき、こんな書き方をする。 Model::withCount('xxxx')->having('xxxx_count', '>', 1); ただ、paginateを付けたい場合 Model::withCount('xxxx')->having('xxxx_count', '>', 1)->paginate(20); とやると、エラーが出る…