PHPackages                             takielias/lab - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. takielias/lab

ActiveLibrary[Templating &amp; Views](/categories/templating)

takielias/lab
=============

The Laravel Ajax Builder is a Laravel package for easily creating AJAX JSON responses. It allows setting status codes, messages, views, data, alerts, and redirect URLs through a fluent interface, streamlining the process of sending AJAX responses in Laravel applications.

1.1.1(2w ago)11.1k↑66.7%1MITPHPPHP ^8.3

Since May 1Pushed 2w ago1 watchersCompare

[ Source](https://github.com/takielias/laravel-ajax-builder)[ Packagist](https://packagist.org/packages/takielias/lab)[ Docs](https://github.com/takielias/laravel-ajax-builder)[ RSS](/packages/takielias-lab/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (14)Versions (26)Used By (1)

Laravel Ajax Builder
====================

[](#laravel-ajax-builder)

[![tests](https://github.com/takielias/laravel-ajax-builder/actions/workflows/tests.yml/badge.svg)](https://github.com/takielias/laravel-ajax-builder/actions/workflows/tests.yml)[![lint](https://github.com/takielias/laravel-ajax-builder/actions/workflows/lint.yml/badge.svg)](https://github.com/takielias/laravel-ajax-builder/actions/workflows/lint.yml)[![Latest Version](https://camo.githubusercontent.com/6cf7e82fceaf2360b2d2b50eefa32247b7beedfe46594f859b8d0e6fa558c91b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74616b69656c6961732f6c61623f636f6c6f723d626c7565266c6162656c3d72656c65617365267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/takielias/lab)[![Total Downloads](https://camo.githubusercontent.com/407025a2cae058c6d757741b5c5bd0d31030467c21e7f9009345b81d2b98b39c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74616b69656c6961732f6c61622e7376673f636f6c6f723d7267622532383234392532303131352532303232253239267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/takielias/lab)[![PHP Version](https://camo.githubusercontent.com/9aab98a73b8669e3c8fb602449bc6384dfd9930b5dc15e2714b9e8c25f390e32/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f74616b69656c6961732f6c61622f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/takielias/lab)[![Laravel](https://camo.githubusercontent.com/62fb51ff79bc0448b06c3fa93215117523c890e8ba160cb0d32591b5072017f0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d3131253230253743253230313225323025374325323031332d4646324432303f7374796c653d666f722d7468652d6261646765266c6f676f3d6c61726176656c)](https://packagist.org/packages/takielias/lab)[![License](https://camo.githubusercontent.com/3509fbf7f5bec00ca5d76943e3fd9234f191653775ecda89820740b2803e88c3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f74616b69656c6961732f6c61623f7374796c653d666f722d7468652d6261646765)](https://github.com/takielias/laravel-ajax-builder/blob/main/LICENSE.md)[![Stars](https://camo.githubusercontent.com/08310cf05c6023bc4c2107239f5bc6c7361e305ff0b71f077379066dbd0b2ed4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f74616b69656c6961732f6c61726176656c2d616a61782d6275696c6465723f636f6c6f723d7267622532383036253230313839253230323438253239266c6162656c3d7374617273267374796c653d666f722d7468652d6261646765)](https://github.com/takielias/laravel-ajax-builder)[![Forks](https://camo.githubusercontent.com/a114b51a242424cd85e70a2954fa32a3824ae4b443129ff343be9561168b3750/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f74616b69656c6961732f6c61726176656c2d616a61782d6275696c6465723f636f6c6f723d7267622532383133342532303131352532303232253239267374796c653d666f722d7468652d6261646765)](https://github.com/takielias/laravel-ajax-builder)[![Issues](https://camo.githubusercontent.com/f5ae702394760c80cc5732a934de0383846b5ebe9e2c84c2385dccbdbbf67ad9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f74616b69656c6961732f6c61726176656c2d616a61782d6275696c6465723f636f6c6f723d726762253238313334253230323339253230313238253239267374796c653d666f722d7468652d6261646765)](https://github.com/takielias/laravel-ajax-builder)[![Linkedin](https://camo.githubusercontent.com/65e57dee4eb0633fbca0429b13af9bcaa0e812e98f96c849653f970942fc7e9b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f2d4c696e6b6564496e2d626c61636b2e7376673f6c6f676f3d6c696e6b6564696e26636f6c6f723d72676261283233352532303638253230353029267374796c653d666f722d7468652d6261646765)](https://linkedin.com/in/takielias)

### Fluent AJAX response builder for Laravel — fetch + FormData on the client, no jQuery.

[](#fluent-ajax-response-builder-for-laravel--fetch--formdata-on-the-client-no-jquery)

For an enhanced user experience, it is highly recommended to integrate this package with the [Laravel Tablar](https://github.com/takielias/tablar) admin dashboard.

Requirements
------------

[](#requirements)

ComponentMinimumPHP8.3Laravel11.x / 12.x / 13.xNode22 LTS (only needed if you bundle the JS helpers)Installation
------------

[](#installation)

```
composer require takielias/lab
```

```
php artisan lab:install
```

Then build assets with your existing pipeline (`npm run build` for Vite, or copy the published JS into your bundler entrypoint).

JavaScript usage (no jQuery)
----------------------------

[](#javascript-usage-no-jquery)

The package ships native `window.ajax*` helpers that wrap `fetch` + `FormData`. The CSRF token is read from ``automatically.

```

    @csrf

    Save

    // fired automatically when .ajax-submit-button is clicked, but you
    // can also call the helpers directly:
    document.getElementById('manual-trigger').addEventListener('click', () => {
        const data = new FormData(document.getElementById('ajax-form'));
        window.ajaxPost('/products', data,
            (response) => console.log('saved', response),
            (error)    => console.error('failed', error),
            ()         => console.log('done')
        );
    });

```

Usage
-----

[](#usage)

Insert `@alert` where you want the alert messages to appear in your Blade file. And put your form submit button as `@submit`

Example
-------

[](#example)

```

        Slip form

        @alert

      ...............
      ...............

        @submit

```

Controller
----------

[](#controller)

```
    function store(SaveProductRequest $saveProductRequest)
    {
        $validated = $saveProductRequest->validated();
        Product::create($validated);
        return Lab::setData(['success' => true])
            ->enableScrollToTop()
            ->setRedirect(route('product.index'))
            ->setSuccess('Product Created Successfully')
            ->setStatus(201)
            ->toJsonResponse();
    }
```

Request
-------

[](#request)

For request validation

```
