// สำหรับหลาย ๆ คนจัดหาอาร์เรย์ของข้อมูล 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();
// การโทรหลายครั้งไปยังวิธีการที่สร้างที่ไหนและและ ... // // การโทรหรือที่ไหนไปและหรือ 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(); // retuns จริงถ้ามีอยู่
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.course_id = courses.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 ไฟล์การโยกย้ายทั้งหมดจะถูกจัดกลุ่มเป็นไฟล์ 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 จัดการ make: 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 วิธีเช่น Send และ JSON ส่ง () ส่งการตอบกลับข้อความธรรมดาในขณะที่ JSON ส่ง respeonse ที่จัดตั้งขึ้น JSON
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 (' ผู้ดูแลระบบ/แดชบอร์ด ')}}'> แดชบอร์ด 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> // จะพาคุณไปยังผู้ใช้/โปรไฟล์