[Vuejs]-Flash messages display and sometimes they don't

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.

Leave a comment