Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/takielias/laravel-ajax-builder
A simpel Laravel package for easy jQuery AJAX calls and response builder.
https://github.com/takielias/laravel-ajax-builder
ajax blade jquery laravel
Last synced: 8 days ago
JSON representation
A simpel Laravel package for easy jQuery AJAX calls and response builder.
- Host: GitHub
- URL: https://github.com/takielias/laravel-ajax-builder
- Owner: takielias
- License: other
- Created: 2024-05-01T06:30:05.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-11-04T16:02:55.000Z (11 days ago)
- Last Synced: 2024-11-04T16:23:22.349Z (11 days ago)
- Topics: ajax, blade, jquery, laravel
- Language: PHP
- Homepage: https://ebuz.xyz
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- Contributing: contributing.md
- License: license.md
Awesome Lists containing this project
README
# Laravel Ajax Builder
[![Latest Version](https://img.shields.io/packagist/v/takielias/lab?color=blue&label=release&style=for-the-badge)](https://packagist.org/packages/takielias/lab)
[![Stars](https://img.shields.io/github/stars/takielias/laravel-ajax-builder?color=rgb%2806%20189%20248%29&label=stars&style=for-the-badge)](https://packagist.org/packages/takielias/lab)
[![Total Downloads](https://img.shields.io/packagist/dt/takielias/lab.svg?color=rgb%28249%20115%2022%29&style=for-the-badge)](https://packagist.org/packages/takielias/lab)
[![Forks](https://img.shields.io/github/forks/takielias/laravel-ajax-builder?color=rgb%28134%20115%2022%29&style=for-the-badge)](https://packagist.org/packages/takielias/lab)
[![Issues](https://img.shields.io/github/issues/takielias/laravel-ajax-builder?color=rgb%28134%20239%20128%29&style=for-the-badge)](https://packagist.org/packages/takielias/lab)
[![Linkedin](https://img.shields.io/badge/-LinkedIn-black.svg?logo=linkedin&color=rgba(235%2068%2050)&style=for-the-badge)](https://linkedin.com/in/takielias)### This package provides an easy solution for implementing jQuery AJAX calls and managing responses in Laravel applications.
For an enhanced user experience, it is highly recommended to integrate this package with the [Laravel Tablar](https://github.com/takielias/tablar) admin dashboard.
## Installation
```bash
composer require takielias/lab
```````bash
php artisan lab:install
````Now `npm run dev`
## Usage
Insert `@alert` where you want the alert messages to appear in your Blade file. And put your form submit button
as `@submit`## Example
```php
Slip form
@alert
...............
...............
```
## Controller
```php
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
For request validation
```php
*/
public function rules(): array
{
return [
'price' => ['required', 'gt:0'],
'name' => ['required']
];
}protected function failedValidation($validator)
{
// Throw the HttpResponseException with the custom response
throw new HttpResponseException(Lab::setStatus(422)
->enableScrollToTop()
->setValidationError($validator)->toJsonResponse());
}
}```
## Ajax Call
```js
const productData = {
product_name: 'Product Name'
};
const postUrl = '{{route('
product.save
')}}';
ajaxPost(postUrl, productData, function (response) {
console.log(response.data)
}, function (error) {
}, function (data) {
})
```There are also some built in Method ajaxGet, ajaxPost, ajaxPut & ajaxPatch
## Change log
Please see the [changelog](changelog.md) for more information on what has changed recently.
## Testing
```bash
composer test
```## Contributing
Please see [contributing.md](contributing.md) for details and a todolist.
## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Author Name][link-author]
- [All Contributors][link-contributors]## License
MIT. Please see the [license file](license.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/takielias/lab.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/takielias/lab.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/takielias/lab/master.svg?style=flat-square
[ico-styleci]: https://styleci.io/repos/12345678/shield
[link-packagist]: https://packagist.org/packages/takielias/lab
[link-downloads]: https://packagist.org/packages/takielias/lab
[link-travis]: https://travis-ci.org/takielias/lab
[link-styleci]: https://styleci.io/repos/12345678
[link-author]: https://github.com/takielias
[link-contributors]: ../../contributors