0👍
Since you are using ajax to store your data, you will need to provide the message as a response in that request. So basically the store
method on your controller would look like
public function store(Request $request)
{
$school = School::create([
'name' => $request->name,
]);
return response($school, 201);
}
201 is the HTTP code to indicate a resource was created, and the by the RFC you should return the resource in the response.
In your Vue file, the store
method would then be
store()
{
axios.post('/master/schools', {
name: this.name,
}.then((response) => {
this.name = ''
// Modify your DOM or alert the user
alert('Resource created')
}));
}
As a recomendation, you should aways validate user input before storing.
- [Vuejs]-How to test this component?
- [Vuejs]-How can I solve Vue.js original tag error in index,html tagl?
Source:stackexchange.com