$query = ¥DB::table('nekos');
dump($query->toSql()); // "select * from `nekos`"
$value1 = $query->count('id'); // 件数
$value2 = $query->max('neko_val'); // 最大
$value3 = $query->min('neko_val'); // 最小
$value4 = $query->avg('neko_val'); // 平均
$value5 = $query->sum('neko_val'); // 合計
¥DB::table('nekos')->orderBy('id')->chunk(4, function ($chunk) {
dump(count($chunk));// → 4 → 4件ずつDBからデータ取得していることを意味している。
foreach ($chunk as $ent) {
$ent = (array)$ent;
// ~ なんらかの処理
}
});
ダンプ
$res = ¥DB::table('nekos')->where('id', 4)->exists(); // true:レコード存在, false:存在しない
$query = ¥DB::table('nekos')
->offset(10)
->limit(5);
dump($query->toSql()); // → "select * from `nekos` limit 5 offset 10"
$data = $query->get();
dump($data);
$query = ¥DB::table('nekos')->orderBy('neko_name');
dump($query->toSql()); // → "select * from `nekos` order by `neko_name` asc"
$data = $query->get();
dump($data);
DESC
$query = ¥DB::table('nekos')->orderBy('neko_name', 'desc');
dump($query->toSql()); // →"select * from `nekos` order by `neko_name` desc"
$data = $query->get();
dump($data);
$query = ¥DB::table('nekos')->
whereRaw('neko_val = 4')->
orderByRaw('neko_name desc');
dump($query->toSql()); // →"select * from `nekos` where neko_val = 4 order by neko_name desc"
$data = $query->get();
dump($data);
$query = ¥DB::table('nekos')->
select('id', 'neko_name as cat', 'neko_val', 'neko_date');
dump($query->toSql()); // →"select `id`, `neko_name` as `cat`, `neko_val`, `neko_date` from `nekos`"
$data = $query->get();
dump($data);
$query = ¥DB::table('nekos')->
selectRaw('id, neko_name, neko_val as CatValue');
dump($query->toSql()); // →"select id, neko_name, neko_val as CatValue from `nekos`"
$data = $query->get();
dump($data);
SESSION_DRIVER=database
'driver' => env('SESSION_DRIVER', 'database')
cd ルートディレクトリへのパス
php artisan session:table
php artisan migrate
¥Session::put('neko_key', '赤猫');
// 配列も指定可能
¥Session::put('dog_key', ['dog_name'=>'白犬', 'age'=>10]);
$value = session('neko_key');
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
注意事項