Hướng dẫn dynamically load content in bootstrap modal with ajax laravel - tải động nội dung trong phương thức bootstrap với ajax laravel
Bootstrap Modal là một hộp bật lên sử dụng để hiển thị thông tin và hình thức nhập. Show
Bạn cũng có thể cập nhật nội dung của nó một cách linh hoạt mỗi lần khi mở bằng AJAX. Trong hướng dẫn này, tôi chỉ ra cách bạn có thể tải nội dung trên phương thức Bootstrap một cách động bằng cách sử dụng JQuery Ajax trong Laravel 9.
Nội dung
1. Cấu hình cơ sở dữ liệuDatabase ConfigurationMở tệp php artisan make:migration create_employees_table1. Chỉ định máy chủ, tên cơ sở dữ liệu, tên người dùng và mật khẩu. DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=tutorial DB_USERNAME=root DB_PASSWORD= 2. Cấu trúc bảngTable structure
php artisan make:migration create_employees_table
public function up() { Schema::create('employees', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('username'); $table->string('name'); $table->string('email'); $table->smallInteger('age'); $table->timestamps(); }); }
php artisan migrate
3. Mô hìnhModel
php artisan make:model Employees
Đã hoàn thành mã
php artisan make:controller EmployeesController
Tạo 2 phương pháp -
Trả lại public function up() { Schema::create('employees', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('username'); $table->string('name'); $table->string('email'); $table->smallInteger('age'); $table->timestamps(); }); }9 ở định dạng JSON. Đã hoàn thành mã get(); return view('index',$data); } public function getEmployeeDetails($empid = 0){ $employee = Employees::find($empid); $html = ""; if(!empty($employee)){ $html = " 4. Bộ điều khiểnRoute
name('getEmployeeDetails'); GetEmployedEtails () - Phương thức này lấy ID nhân viên làm A & NBSP; tham số. Lấy bản ghi bằng public function up() { Schema::create('employees', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('username'); $table->string('name'); $table->string('email'); $table->smallInteger('age'); $table->timestamps(); }); }5 từ bảng php artisan make:migration create_employees_table2 và tạo bố cục. Gán public function up() { Schema::create('employees', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('username'); $table->string('name'); $table->string('email'); $table->smallInteger('age'); $table->timestamps(); }); }7 cho public function up() { Schema::create('employees', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('username'); $table->string('name'); $table->string('email'); $table->smallInteger('age'); $table->timestamps(); }); }8.ViewTrả lại public function up() { Schema::create('employees', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('username'); $table->string('name'); $table->string('email'); $table->smallInteger('age'); $table->timestamps(); }); }9 ở định dạng JSON. 5. Tuyến đường Mở tệp php artisan migrate0. Xác định 2 tuyến đường - / - Tải public function up() { Schema::create('employees', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('username'); $table->string('name'); $table->string('email'); $table->smallInteger('age'); $table->timestamps(); }); }3 Xem. /getemployedeedetails - Đây là cách loại tuyến cho yêu cầu AJAX.
Đã hoàn thành mã php artisan make:migration create_employees_table0 4. Bộ điều khiểnDemoTạo bộ điều khiển php artisan make:migration create_employees_table9. Nhập mô hình php artisan make:migration create_employees_table6.ConclusionTạo 2 phương pháp - Index () - Tìm nạp tất cả các bản ghi từ bảng |