You have personal_id in the Request, not customer_id. Change either the form
Input name, or the validation rule key
Jan 9, 2023
9
Level 1
Illuminate\Validation\ValidationException: The customer id field is required
public function update(Request $request,Finance $finances,$id)
{
try{
$this->validate($request, [
'customer_id' => 'required|exists:customers,personal_id',
'test_id' => 'required|exists:p_tests,id',
'amount' => 'required|integer',
'date' => 'required'
]);
$test = PersonalTest::findOrFail($request->id);
$finances ->update([
'customer_id' => $finances->customer->id,
'test_id' => $test->id,
'date' => $request->date,
'amount'=>$request->amount,
'note'=>$request->note
]);
return redirect()->back()->with('success', 'تم تحديث معلومات مالية جديدة');
}catch(Exception $ex){
// dd($request);
return $ex;
return redirect()->back()->with('message', 'حدث خطعأ ما ');
}
}
Illuminate\Http\Request {#43 ▼ // app\Http\Controllers\FinanceController.php:91
+attributes: Symfony\Component\HttpFoundation\ParameterBag {#45 ▼
#parameters: []
}
+request: Symfony\Component\HttpFoundation\InputBag {#44 ▼
#parameters: array:7 [▼
"_token" => "YZqAXiU1e95ASZyZ1u9Beu2wgxdUMTUQOObHyhFR"
"_method" => "PUT"
"personal_id" => "12345678"
"test_id" => "1"
"amount" => "2100"
"date" => "2023-01-09"
"note" => null
]
}
+query: Symfony\Component\HttpFoundation\InputBag {#51 ▶}
+server: Symfony\Component\HttpFoundation\ServerBag {#47 ▶}
+files: Symfony\Component\HttpFoundation\FileBag {#48 ▶}
+cookies: Symfony\Component\HttpFoundation\InputBag {#46 ▶}
+headers: Symfony\Component\HttpFoundation\HeaderBag {#49 ▶}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/finance/update/1"
#requestUri: "/finance/update/1"
#baseUrl: ""
#basePath: null
#method: "PUT"
#format: null
#session: Illuminate\Session\Store {#375 ▶}
#locale: null
#defaultLocale: "en"
-preferredFormat: null
-isHostValid: true
-isForwardedValid: true
#json: null
#convertedFiles: []
#userResolver: Closure($guard = null) {#178 ▶}
#routeResolver: Closure() {#346 ▶}
basePath: ""
format: "html"
}
Level 104
@moh120 so it should be like this:
<input type="text"
value="{{$finance->customer_id}}"
id="customer_id"
class="form-control"
name="customer_id">
And the Controller action like this; without unnecessary queries and try/catch (handle exceptions in the exceptions Handler.php class:
public function update(Request $request, Finance $finances, $id)
{
$this->validate($request, [
'customer_id' => 'required|exists:customers,personal_id',
'test_id' => 'required|exists:p_tests,id',
'amount' => 'required|integer',
'date' => 'required'
]);
$finances->update([
'customer_id' => $request->customer_id,
'test_id' => $id,
'date' => $request->date,
'amount' => $request->amount,
'note' => $request->note
]);
return redirect()->back()->with('success', 'تم تحديث معلومات مالية جديدة');
}
Please or to participate in this conversation.