• laravel接值的方式:Input(),$request->all(),request()->all()
  • 如果model层继承的是App\Model,就按照以前的做就可以,不需要设置属性
  • 在controller使用ORM模式:
  • <?php
    $post = new Post();
    $post->title = request('title');
    $post->content = request('content');
    $post->save();
    
    
    //第二种
    $param = [
      'title'=>request('title'),
      'content'=>request('content')    
    ];
    post::create($param);
    
    //第三种
    post::create(request(['title','content']));
    //此时会报错 Illuminate \ Database \ Eloquent \MassAssignmentException title
    //解决办法:在model层中的自己所实例化的模型中添加两个属性
    //protected $guarded = []; 不可以注入的字段,将其设置为空也可以
    protected $filltable;可以注入的字段;比如说$filltable = ['title','content'];

     

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄