【Laravel入門】DB::transactionでRequestを使うには?

DB::transactionとは 「DB::transaction」とは、Laravelフレームワークにおけるデータベーストランザクションを操作するためのメソッドです。トランザクションは、一連のデータベース操作が「全て成功する」か「失敗する」のどちらかのプログラムの動きになりま ...
【Laravel入門】middleware(ミドルウェア)とは

middleware(ミドルウェア)とは middlewareとは、HTTPリクエストが送られたタイミングで、受信されてからレスポンスが返されるまでの間に実行される処理をカプセル化したものです。 ミドルウェアはコントローラークラスの前後で処理を行えます。 URL(リクエスト) ↓ ...
【Laravel入門】Route::groupについて学ぶ

Route::groupとは groupとはURIの接頭部や名前空間の接頭部を共通化できます。ルートをグループ化し、共通の属性や中間ウェアを適用するための機能です。この機能を使用することで、同じ属性や中間ウェアを持つ複数のルートをまとめて設定し、コードの重複を減少させることができ ...
SQLSTATE[HY000] [1044] Access denied for user ‘sail’@’%’ to database ‘laravel’

今回は「SQLSTATE Access denied for user 'sail'@'%' to database 'laravel'」についての紹介です。 runするとエラーに Laravel sailのアプリケーションでrun実行時にエラーが発生。 npm run dev ...
【Laravel sailでDB接続エラー】SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘laravel.sessions’ doesn’t exist

エラー文 「run」を実行したときにエラーが発生しました。その原因と解決方法を見ていきましょう。 SQLSTATE: Base table or view not found: 1146 Table 'laravel.sessions' doesn't e ...
【Laravel Sail】Inertia.jsを使ってReactとTypeScript環境構築

今回はLaravel sailを使ってReactとTypeScriptの環境構築の紹介です。 Inertiaとは? Inertia.jsは、クライアントサイドとサーバーサイドの間でデータを非同期的に交換することで、SPAの利点を活用しつつ、従来のサーバーサイドレンダリングの利点を ...
【SQL】pluckでDBを整形して連想配列にする

データベースから取得された結果セットから特定のカラムの値だけを取り出すために使用されるメソッドです。 $user = DB::table('user') ->select('id , 'email') ->get() ->pluck('id', 'email') ->toArra ...
【Laravel入門】Request $requestとは?inputデータをの受信と取得

Request とは? ブラウザから送られるリクエストデータ全部を含むオブジェクトのことです。 「フォームから入力したデータを受け取る」という意味でもあります。 $name = $request->input('name'); $age = $request->input('ag ...
【Laravel入門】Laravel SailでDokerを使って開発環境の構築

今回はSailを使ってLaravel でDokerを使って開発環境の構築をしていきます。 Sailは、Dockerの経験、知見がなくても環境構築ができます。 curl -s アプリ名 | bash
【Laravel】誰でもできるMacにLaravel開発環境構築

今回はPHPの人気フレームワークのLaravelの環境構築をやっていきます。 composer create-project laravel/laravel アプリ名(ディレクトリ名)