1. 程式人生 > >laravel知識點備忘

laravel知識點備忘

1、連表查詢:select * from goods left join shop on goods.shopid=shop.shopid;

DB::table('goods')
  ->leftJoin('shop', 'shop.shopid', '=', 'goods.shopid')
  ->get();

2、or查詢:select * from goods where (good_name like '%$keyWord%' or shop_name like '%$keyWord%' )

DB::table('goods')
  ->where
(function ($query) use ($keyWord) { $query->where('good_name', 'like', "%{$keyWord}%")->orWhere('shop_name', 'like', "%{$keyWord}%"); })
  ->get();

3、查詢結果轉為陣列:toArray

DB::table('goods')->get()->toArray();