How to reload datatable after form submit in laravel?

Member

by adan , in category: PHP Frameworks , 8 days ago

How to reload datatable after form submit in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , 7 days ago

@adan 

To reload a DataTable after a form submit in Laravel, you can follow these steps:

  1. Create a route in your routes/web.php file to handle the form submission:
1
Route::post('/submit-form', 'FormController@submitForm')->name('submit.form');


  1. Create a controller method to handle the form submission:
1
php artisan make:controller FormController


In the FormController, create a method to handle the form submission:

1
2
3
4
5
6
7
public function submitForm(Request $request)
{
    // Handle the form submission

    // Example: If you want to reload the DataTable after form submission
    return redirect()->back()->with('reload_datatable', true);
}


  1. In your view where the DataTable is displayed, check for the reload_datatable message and reload the DataTable using JavaScript.
1
2
3
4
5
<script>
    @if(session('reload_datatable'))
        location.reload();
    @endif
</script>


By following these steps, the DataTable will be reloaded after the form submission in Laravel.