Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

javascript - 如何在Laravel刀片中的React组件中获取Laravel验证错误(How to get Laravel validation errors in react component which is in Laravel blade)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...