laravel5..4中模型层小结查询与添加及此次添加后的id

查询方式,只查某些字段用get,只查第一条用first

$from_detail = VenousThrombusAnswer::where('venous_thrombosis_risk_assessment_token', $venousThrombosisRiskAssessmentToken)
             ->orderBy('id','desc')
             ->first(['id','total','grade']);

$question_id = VenousThrombusForms::where('question', $venousFormsModel->question)
                                    ->first(['id'])
                                    ->toArray();

添加方式:用save方法


    $this->form_id = 0;
    $this->grade =   1;
    $this->total =   1;
    $this->save();

获取此次后插入的id

$id = $this->id;

获取此次插入后的total

$total = $this->total;

猜你喜欢

转载自blog.csdn.net/qq_40876291/article/details/79922396
今日推荐