我試圖驗證更新方法laravel 5.4以下是我的驗證代碼:自定義驗證用於更新表
$data = $request->only('id', 'name', 'number', 'logo', 'email', 'address', 'city', 'state', 'country', 'type', 'tier', 'is_client');
$company = Companies::find($request->id);
Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required', Rule::unique('companies')->ignore($company->id),
'address' => 'max:255',
'city' => 'max:255',
'state' => 'max:255',
'country' => 'max:255',
]);
但這驗證休息,假設在更新方法我通過名稱空,不扔錯誤代碼422
它顯示這個錯誤,我無法趕上span標記錯誤並顯示
更新
至於建議中的答案我嘗試添加了驗證,並試圖檢查我收到以下錯誤:
Trying to get property of non-object
以下是我更新的代碼:
$data = $request->only(['id', 'name', 'number', 'logo', 'email', 'address', 'city', 'state', 'country', 'type', 'tier', 'is_client']);
$company = Companies::find($request->id);
Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required', Rule::unique('companies')->ignore($company->id),
'address' => 'max:255',
'city' => 'max:255',
'state' => 'max:255',
'country' => 'max:255',
])->validate();
即使我不讓我的$data = request->only()
數組我得到相同的錯誤。
'試圖獲得非對象的屬性' –
@NitishKumar'CompanyController'中的第46行是什麼? –
''email'=>'required',Rule :: unique('companies') - > ignore($ company-> id),' –