I'm new to React.
(我是React的新手。)
I'm using react form component partially in the Laravel blade.(我在Laravel刀片中部分使用了React Form组件。)
Then how can I send validation error messages from controllers to that react component which is resides in the Laravel blade file.(然后,如何将验证错误消息从控制器发送到驻留在Laravel刀片文件中的React组件。)
In my Controller,
(在我的控制器中)
public function store(Request $request)
{
$rules = [
'name' => 'required',
'publish_at' => 'required|datetime'
];
$this->validate($request, $rules);
$book = Book::create([
'name' => $request->name,
'publish_at' => $request->publish_at
]);
return response()->json($book);
}
In my laravel blade,
(在我的laravel刀片中)
<form method="POST" action="patients">
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" placeholder=". . .">
@error('name')
<span class="text-danger">{{ $message }}</span>
@enderror
</div>
<div id="publish_at"></div> <!-- this is react component -->
<button type="submit">Submit</button>
</form>
ask by Hnin Wai Hlaing translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…