兵兵有你

人品好,气质差.丢了工作就回家...

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

关于with的一些用法:(with为链式操作)

$product = self::with('imgs,properties')->find($id);

$product = self::with(['imgs','properties'])->find($id);

$product = self::with(['imgs.imgUrl','properties'])->find($id);

$product = self::with(['imgs'])->with(['properties'])->find($id);

当给关联下的关联属性内容进行排序

$product = self::with(
    ['imgs' =>function($query){
            $query->with(['imgUrl'])->order('order asc');}]
)->with(['properties'])->find($id);    

 关于路由的匹配

//获取最近新品
Route::get('api/:version/product/recent','api/:version.Product/getRecent',[],['id'=>'\d+']);

//获取所有栏目
Route::get('api/:version/category/all','api/:version.Category/getAllCategories');

//以上如果不定义变量约束的话,会根据上下顺序优先访问上面的,造成下在的表达式访问不了. 

 

posted on 2018-05-18 19:51  greatbing  阅读(195)  评论(0编辑  收藏  举报