Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to submit forms via Ajax in Laravel

I'm just wondering how to submit forms with Ajax in Laravel

Laravel itself doesn't provide useful tips or workflow in its documentation

Is there some usefull library idealy as extension of jquery?

Im searching for unobtrusive javasctipt solution

like image 822
Ladislav Janeček Avatar asked Oct 25 '25 07:10

Ladislav Janeček


1 Answers

You are looking for https://github.com/whipsterCZ/laravel-ajax

It does exactly what you want and much more!

sending forms via ajax is simple like this - no configuration needed

HTML

<form action="" class="ajax">...</form>

Controller

public function update(ClientRequest $request, Client $client)
{
    $client->update($request->all());
    $request->session()->flash('success', 'Client has been updated.');

    return \Ajax::redirect(route('clients.index'));
}

It also validate form (through custom FormRequest) and shows errors (in errorBag or directly above inputs)

like image 124
WhipsterCZ Avatar answered Oct 26 '25 21:10

WhipsterCZ