----------------------------------- laraverl笔记 asset('/bs-3.3.5/js/ie-emulation-modes-warning.js'); //会定位到public目录 storage/framework/views //静态页面路径 $results = DB::select('select * from users where id = :id', ['id' => 1]); DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']); $affected = DB::update('update users set votes = 100 where name = ?', ['John']); $deleted = DB::delete('delete from users'); composer update //在composer.json 里面加入要添加的包名 执行这个命令就可以生成出包 {{URL::route('userGetAdd')}} {{URL::action('WebController@getUserSummaryInfoWeb',['app_id'=>$appId])}} 获取url的三种方式 action('FooController@method'); route('test01'); route('testaa'); //as 的名称 return redirect('test02'); //重定向的时候参数route里面的第一个参数不是 as return redirect()->action('UserController@profile', [1]); {{ }} {!! !!} //前面一种会将<span>等html标签打印出来,后面一种不会可以显示出样式 if (view()->exists('emails.customer')) { //判断试题是否存在 //model里面的参数 protected $fillable = ['id']; //$fillab 属性白名单 ,使用create方法插入时只能插入id protected $guarded = ['id','password']; //$guarded 使用create插入时,其它字段都可以,id,password插入不了 //命令 php artisan make:controller PhotoController //生成控制器 php artisan make:model User //创建查询模型 ------------------------- ? $user = AppUser::with('roles')->first(); with? AppFlight::firstOrNew(['name' => 'Flight 10']); ? protected $dates = ['deleted_at']; //软删除 //封装查询orm $list = Tuser::where('role',105)->orderBy('username','asc')->take(2)->get(); $list = $list->toArray(); //如果没有查找到转数组会报错,如果没找到不转数组会显示null $count = AppFlight::where('active', 1)->count(); $max = AppFlight::where('active', 1)->max('price'); $list = Tuser::where('role',105)->where('status','<>','normal')->update(['password'=>123456]); UserCumulate::where('app_id', '=', $app_id)->get()->isEmpty(); //添加 $user = new Tuser(); $user->username = 'sssss'; $user->password = '123456'; $user->save(); //删除 $flight = AppFlight::find(1); $flight->delete(); $deletedRows = AppFlight::where('active', 0)->delete(); AppFlight::destroy(1); AppFlight::destroy([1, 2, 3]); AppFlight::destroy(1, 2, 3); AppFlight::firstOrCreate(['name' => 'Flight 10']); //将按照字段查找,找不插入,不存在插入操作 AppFlight::firstOrNew(['name' => 'Flight 10']); ? User::where(function($query) { $query->where('name', '=', 'John') ->orWhere('votes', '>', 100); }) ->get(); select * from `users` where `users`.`deleted_at` is null and `name` = 'John' or `votes` > 100 $list = Tuser::find(22)->Quiz()->get()->first()->quiz_name; //外链到其它表查询 //一对多 WAccoun UserSummary 微信号表A 微信号每日信息表B 1 多 A表中的一个微信号在B表中会有多条数据 B表中每条微信号信息 在A只会对应一条信息 A表和B表是1对多的关系 A表中是 return $this->hasMany('AppUserSummary', 'app_id', 'app_id'); B表中是 return $this->belongsTo('AppWAccount', 'app_id', 'app_id'); //一对一是 hasOne //多对多 是 belongsToMan return $this->belongsToMany('AppRole'); return $this->belongsToMany('AppRole', 'user_roles'); $user = AppUser::find(1); foreach ($user->roles as $role) { // }