自動搜索控制器 'controller_auto_search' => true, 只有在應用配置文件裏修改才起做用api
多級控制器 路由:'api/v1/:a/:b/:c' => 'api/v1.:a.:b/:c'數組
'api/v1/user/saler/auth'=>'index/index/index',app
'api/v1/user/saler/auth'=>'api/v1.user.Saler/auth',this
模型查詢出來的結果都是模型對象或模型對象的集合url
$user = new UserModel(); $output = $user->field('userid,name')->where('userid', $userid)->find(); $list = $user->field('userid,name')->where('userid', $userid)->whereor('role',2)->limit(0,10)->select();
$list = Db::table('t_product') ->where('productid','IN',function($query) use($myid) { $query->table('t_follow_product')->where('userid',$myid)->field('productid'); }) ->column('productid,name');
$m = new AuthModel(); $m->field('userid,auth_state') // 必須得有userid,不然hasOne不會觸發 ->with('user') ->where('userid',$userid) ->find(); class Auth extends Model { public function user() { return $this->hasOne('User','userid')->bind('role,name,head_img_url'); } }
刪除條件必須是主鍵,若是不是主鍵,必須用wherecode
UserModel::destroy(['userid'=>$userid]); $m->where('name',$name)->delete();
$user = new UserModel(); $user->mobile = $mobile; $user->password = $password; $res = $user->save(); $id = $user->userid
$user = new UserModel(); $user->save(['name'=>'haha'],['userid'=>$userid]);
$list = User::all(); if($list) { $list = collection($list)->toArray(); }
新增屬性必須得賦值對象
$user->append(['code']); $user->code = 0;
能夠獲取一個不存在的字段,若是觸發這個不存在的字段可使用append()路由
public function getCompanyNameAttr($value, $data) { if (array_key_exists('company_id', $data)) { $company_id = $data['company_id']; return UserModel::where('userid',$company_id)->value('name'); } return ''; } $output->append(['company_name','code','msg']);