laraverl笔记

-----------------------------------  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 = App\User::with('roles')->first();    with?
App\Flight::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 = App\Flight::where('active', 1)->count();
$max = App\Flight::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 = App\Flight::find(1);
$flight->delete();
$deletedRows = App\Flight::where('active', 0)->delete();
App\Flight::destroy(1);
App\Flight::destroy([1, 2, 3]);
App\Flight::destroy(1, 2, 3);
App\Flight::firstOrCreate(['name' => 'Flight 10']);     //将按照字段查找,找不插入,不存在插入操作
App\Flight::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('App\UserSummary', 'app_id', 'app_id');
B表中是
return $this->belongsTo('App\WAccount', 'app_id', 'app_id');

//一对一是  hasOne
//多对多 是  belongsToMan
return $this->belongsToMany('App\Role');
return $this->belongsToMany('App\Role', 'user_roles');

$user = App\User::find(1);
foreach ($user->roles as $role) {
    //
}

 

转载于:https://www.cnblogs.com/suxiaolong/p/6644239.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值