zzz

Like trang page giúp ad nhé! THANK ALL

Thứ Tư, 4 tháng 11, 2015

[Laravel-5]-bài 9: Schema Builder cơ bản P2


 1. Tạo migration
lệnh : php artisan make:migration create_abc_table --create=abc // viết y hệt, thay mỗi abc = tên bảng.

2. vào file bảng , tạo các trường

3. chạy lệnh để update vào csdl
php artisan migrate          // update lại bảng
php artisan migrate:refresh  // refresh lại lệnh update khi chỉnh sửa cột, -> làm mới bảng

4. Seeding : tạo dữ liệu mẫu
========================================
5. TRUY VẤN DỮ LIỆU
a. lấy tất cả bản ghi ra
Route::get('query/select-all', function(){
   $data = DB::table('proudct')->get();  // code lấy toàn bộ dữ liệu
   echo "<pre>";
   print_r($data);
   echo"</pre>";
});

b. lấy 1 cột dữ liệu thôi
Route::get('query/select-col', function(){
   $data = DB::table('proudct')->select('name')->get();
   echo"<pre>"
   print_r($data);
   echo "</pre>";
});

c. lấy bản ghi có điều kiện id = x
Route::get('query/select-col', function(){
   $data = DB::table('proudct')->select('name')->where('id',4)->get();
   echo"<pre>"
   print_r($data);
   echo "</pre>";
});
d. lấy bản ghi có điều kiện or
Route::get('query/select-col', function(){
   $data = DB::table('proudct')->select('name')->where('cate_id',2)->orWhere('price', 500)->get();
   echo"<pre>"
   print_r($data);
   echo "</pre>";
});
e. lấy bản ghi có điều kiện add
Route::get('query/select-col', function(){
   $data = DB::table('proudct')->select('name')->where('cate_id',2)->where('price', 500)->get();
   echo"<pre>"
   print_r($data);
   echo "</pre>";
});

Không có nhận xét nào:

Đăng nhận xét