Hello, welcome to this question post.
I was looking for quick and succint turn around for this question and after searching lot on this one of post gave me any idea to update my rest of non-validate fields of form and also which don’t have validate rules at laravel model or controller level.
So here if my modified update() function from laravel Controller to update non required form fields or rules set in laravel controller or model, with in easy simple PHP style.
public function update(Request $request, $id)
{
$validatedData = $request->validate([
'name' => 'required|max:255',
'price' => 'required',
]);
$nonRequiredFields = [
'discount' => $request->discount,
'qty' => $request->qty,
'tax'=> $request->tax,
'shipping' => $request->shipping,
'handling' => $request->handling,
];
Food::where('foodId', '=', $id)->update(array_merge($validatedData, $nonRequiredFields));
return redirect()->route('food.index')->with('success', 'Food successfully updated');
}
In the code above I have given readable name to variable ($nonRequiredFields) which can be easily understand and I found this way the solution is working!
If you know more better approach kindly send me a not or if comments are open to this post please do comment.
Thanks for visiting and reading the post.
Break! I didn’t plan it. One day I just didn’t feel like opening Instagram—and then…
AI tools Let’s be real—AI sounds like either a robot apocalypse or something only tech…
Summer vacation is a great time for kids to explore, have fun, and learn new…
Goal: Understand transformers, large language models, and the architecture behind ChatGPT. Tutorial Suggestions: ✅ “Transformers…
Goal: Build apps or tools with ChatGPT or GPT-4 API. Tutorial Suggestions: ✅ OpenAI API…
Goal: Learn how to prompt better, write content, brainstorm, code, etc. Tutorial Suggestions: ✅ OpenAI's…