//多くの場合、データの配列を提供します。 DB::table('table_name')->save($data);
DB::lastId();
DB::table('table_name')->where('id', 1)->update($data);
DB::table('table_name')->where('id', 1)->delete();
DB::table('table_name')->delete();
DB::affectedRows();
DB::table('table_name')->get(); //すべての列を返します
$columns = 'column1, column2, column3 columnn' //文字列として
または
$columns = ['column1', 'column2', 'column3', 'columnn'] //配列DB::table('table_name')->get($columns);
DB::table('table_name')->where('id', 1)->get();
//メソッドがwhere and and ... // call or where to and and anまたはDB::table('table_name')->where('id', 1) ->where('age', 20 , '>')->where('gender', 'Male')->get();
DB::table('table_name')->row()->where('id', 1)->get();
または
DB::table('table_name')->find(1); //デフォルトの列名は「ID」です
DB::table('table_name')->where('id', 1)->value();
DB::table('table_name')->where('id', 1)->count(); DB::table('table_name')->count(); //条件なしのすべての行
DB::table('table_name')->where('id', 1)->max(); DB::table('table_name')->where('id', 1)->min(); DB::table('table_name')->where('id', 1)->avg();
DB::table('table_name')->distinct()->get(); //すべてではない場合、列を供給します//条件付きDB::table('table_name')->distinct()->where('id', 1)->get();
DB::table('table_name')->join('table2', 'table1.primary', 'table2.foregin')->get();
//結合メソッドを複数回呼び出して、内側結合を使用してmutlipleテーブルに参加します。結合メソッドのその他のオプションにはleftJoin(), rightJoin,() unionJoin()が含まれます。
DB::table('table_name')->between('age', 20, 25)->get();
DB::table('table_name')->range(1, 25)->get();
DB::table('table_name')->where('id', 1)->exits(); //存在する場合はtrueをretunします
DB::table('table_name')->where('id', 1)->doesNotExist(); //存在するoposite
Database::switchTo('database_name'); //ここからクエリを開始します
DB::table('table_name')->use('database_name', 'table')->get();
$interns = new Intern($data); $interns->save();
$interns->affectedRows();
$interns->lastId();
$interns = new Intern(); $interns->name = "Godwin"; $interns->age = 20; $inters->save();
Intern::find(1)->update($data);
Intern::find(5)->delete();
Intern::all(); // DB::table('interns')->get();
Intern::where('id', 1)->get(); //同じDB::table('interns')->where('id', 1)->get();
Intern::find(1);
Intern::with('course')->get(); //これは、インターンとコースのテーブルがID列をその主キーとして使用し、インターンの内側の結合コースを形成すると仮定します。
Interns::with('course')->join('supervisor', 'interns.supervisor_id', 'supervisor.id')->get();
DB::query('SELETE * FROM interns WHERE age > ?')->bindings([20])->get();
php manage make:dbデータベース名が.env構成で指定されていない場合、 php manage make:db dbnameを使用しますphp manage make:migration create_migration_nameこれにより、データベース/移行ディレクトリの下で移行ファイルが作成されます。 (テーブル名は複数形である必要があります) php manage migrateこれにより、すべての移行が実行されますphp manage migrate --file=filenameこれは、単一のファイルのマイジェーションを実行します。 (ファイル拡張子を入れないでください) php manage migrate:groupすべての移行ファイルは1つのSQLファイルにグループ化されますphp mange migrate:group --runグループ化された移行が実行されますphp manage migrate:modifiyこれにより、移行の変更が実行されますphp manage migrate:listリストすべての実行移行php manage migrate:rollbackロールバック移行php manage migrate:refresh 、移行を再実行しますphp manage migrate:log移行エラーphp manage migrate:log --clear移行エラーをクリアしますコントローラーを作成:| php manage make:controller ControllerName
リソースコントローラーを作成:| php manage make:controller ControllerName --resource
モデルを作成:| php manage make:model ModelName
モデルとその移行を作成します:| PHP管理メイク:Model -M ModelName
public function saveUser(Request $request) { $name = $request->post('name'); // get the value of name sent through an HTTP POST echo $name; }
//またはpublic function saveUser(Request $request) { $name = $request->name; //dynamically assigned properties the Request Class echo $name; }
//またはpublic function saveUser(Request $request) { $name = $request->body->name; //dynamically assigned properties the Request Class echo $name; }
public function saveUser(Request $request) { $name = $request->get('name'); // get the value of name sent through an HTTP GET echo $name; }
//またはpublic function saveUser(Request $request) { $name = $request->name; echo $name; }
//またはpublic function saveUser(Request $request) { $name = $request->params->name; echo $name; }
応答クラスには、2つのメソッド、つまり送信とJSONがあります。 send()JSONがJSONフォーミングされたRespeonseを送信している間、単純なテキスト応答を送信します。
public function login(Request $request) { $email = $request->post('email'); return response()->send(200, $email); }
public function login(Request $request) { $email = $request->post('email'); return response()->json(200, $email); // can be received through the message property }
redirect('user/dashboard');
redirect()->back();Route::get('user/profile', [UserController::class, 'userProfile']); Route::post('user/profile', [UserController::class, 'userProfile']); Route::group(['prefix' => 'admin', function(){ Route::get('/dashboard', [AdminController::class, 'index']); });テンプレート `<a href = '{{url(' admin/dashboard ')}}'>ダッシュボードRoute::resource('products', ProductController::class); //製品はルートのプレフィックスですRoute::resource('products', ProductController::class)->except(['destroy']); Route::post('user/profile', [UserController::class, 'userProfile'])->name('user.p');<a href='{{ route('user.p') }}'>Dashboard</a> //ユーザー/プロフィールに移動します