zoukankan      html  css  js  c++  java
  • 关联模型的一些用法

    关于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');

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

     

  • 相关阅读:
    注册验证
    翻页加输入框
    php面向对象
    封装数据库
    浅谈BFC和haslayout
    总结JS面向对象
    总结(JS)
    转载6
    总结(5.30)
    总结(5.29)
  • 原文地址:https://www.cnblogs.com/bing2017/p/9057798.html
Copyright © 2011-2022 走看看