我有一個簡單的模型IsolatedQuery
其中包括一個name
和query
字段。我已經在模型的$fillable
屬性中定義了這兩個字段。該IsolatedQueryController @店看起來是這樣的:
public function store(IsolatedQueryRequest $request)
{
IsolatedQuery::insert($request->all());
session()->flash('flash_message', 'Isolated Query succesvol opgeslagen');
return redirect('iq');
}
爲了完整起見,這裏是Model的源(這是我將其形容爲小)
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class IsolatedQuery extends Model
{
protected $fillable = [
'name',
'query'
];
}
的IsolatedQueryRequest
只需要兩個name
和query
是充滿了任何價值。
當使用給定名稱和查詢值調用store
方法時,出現錯誤:SQLSTATE[42S22]: Column not found: 1054 Unknown column '_token' in 'field list'
。
很明顯,一個_token
字段獲取請求發送,但我有點困惑,爲什麼它試圖存儲它與實際的SQL查詢,因爲它沒有列在$fillable
數組中。
爲什麼它得到質量分配?
可能重複[Laravel 5.2 $ fillable](http://stackoverflow.com/questions/34864666/laravel-5-2-fillable) – bishop
@bishop這不是重複的,這個問題問它爲什麼會發生,你鏈接到不回答。此外,這個問題是關於使用可填寫的proprty,另一個是關於不使用它。 –
確實不是重複的。我想應用'$ request-> all()'應該可以,而不是調用'$ request-> only''。如果我想要的話,我不需要用'$ fillable'來定義批量賦值列表。 – Ben