-3

I'm looking for some unobtrusive ajax solution for Laravel.

for example Nette Framework has implemented own ajax workflow to do this.

but laravel doesn’t provide anything like this…

Edit: Of course, i know that i can do that with jQuery and JsonResponse but question is if there sofiscitated solution

1 Answers1

1

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

It does exactly what you want and much more!

I assume that you want to send some ajax request and you want to redraw some updated content after response

its quite simple Blade Template

@section('dynamic')
   <div id='greeting'>Hello {{name}}</div>
@endSection()    
<a href="/changeName?name=Láďo" class="ajax"></a>

Laravel action

public function changeName(Request $request, Ajax $ajax) {
    return $ajax
        ->redrawSection('dynamic')
        ->view('welcome',  ['name'=>$request->get('name')] )
}

You don't have to render whole page, you can just replace or append some html by ID.. it can do almost everything :)

public function redrawPartial(Request $request, Ajax $ajax) {
    return $ajax
        ->redrawView('greeting')
    //  ->appendView('greeting') 
        ->view('partials._greeting',  ['name'=>$request->get('name')] )
}
WhipsterCZ
  • 638
  • 1
  • 8
  • 13
  • If you are familiar with Nette Framework you are at home... this is inspired by Nette :) It is basically AJAX Workflow for Laravel. – WhipsterCZ Apr 29 '16 at 16:31