laravel 過濾非數據庫字段

                                                                                                                          或許不足,歡迎補充呀!                      (•́へ•́╬)

 

第一種 用php 的 unset,嗯,直接銷燬有點暴力!

unset($input['testField'],$input['testField2'])

第二種 用request的 only except 方法

$request->only('field','field2')     // 獲取field和field2的數據集

$request->except('field')           //獲取除field以外的數據集

第三種,在模型上指定  fillable guarded屬性          (此方法僅對create操作有效)

    protected  $fillable=['testField'];   //加入白名單
    protected  $guarded =['testField'];    //加入黑名單

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章