|
| 1 | +# Laravel SSP-INIT |
| 2 | + |
| 3 | +SSP-INIT is a Laravel package designed to facilitate server-side processing (SSP) for Eloquent models, supporting dynamic filtering, sorting, and pagination. This package simplifies the development of data-intensive applications by abstracting complex server-side operations. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Dynamic Filtering**: Apply filters based on request parameters. |
| 8 | +- **Sorting**: Sort data by any model attribute. |
| 9 | +- **Pagination**: Efficiently paginate the data based on the client's request. |
| 10 | +- **Eager Loading**: Supports eager loading of relationships to optimize query performance. |
| 11 | +- **Response Encoding**: Optionally encode the response data. |
| 12 | + |
| 13 | +## Requirements |
| 14 | + |
| 15 | +- PHP ^8.2 |
| 16 | +- Laravel ^8.0 |
| 17 | + |
| 18 | +## Installation |
| 19 | + |
| 20 | +To install the SSP-INIT package, run the following command in the root of your Laravel project: |
| 21 | + |
| 22 | +```bash |
| 23 | +composer require mrkacmaz/laravel-ssp |
| 24 | +``` |
| 25 | + |
| 26 | +## Usage |
| 27 | +Here is a basic example of how to use the SSP trait in a Laravel controller: |
| 28 | + |
| 29 | +### Controller |
| 30 | +```php |
| 31 | +<?php |
| 32 | + |
| 33 | +namespace App\Http\Controllers; |
| 34 | + |
| 35 | +use Mrkacmaz\LaravelSsp\Traits\SSP; |
| 36 | +use App\Models\User; |
| 37 | +use Illuminate\Http\Request; |
| 38 | + |
| 39 | +class UserController extends Controller |
| 40 | +{ |
| 41 | + use SSP; |
| 42 | + |
| 43 | + public function index(Request $request) |
| 44 | + { |
| 45 | + if ($request->expectsJson()){ |
| 46 | + $data = self::processSSP($request, User::class); |
| 47 | + return response()->json($data); |
| 48 | + } |
| 49 | + return view('welcome'); |
| 50 | + } |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +### Blade File |
| 55 | +```blade.php |
| 56 | +<x-app-layout> |
| 57 | + <table class="table table-hover"> |
| 58 | + <thead> |
| 59 | + <tr> |
| 60 | + <th scope="col">#</th> |
| 61 | + <th scope="col">Full Name</th> |
| 62 | + <th scope="col">Email</th> |
| 63 | + </tr> |
| 64 | + </thead> |
| 65 | + <tbody></tbody> |
| 66 | + </table> |
| 67 | +</x-app-layout> |
| 68 | +``` |
| 69 | + |
| 70 | +### JS File |
| 71 | +```js |
| 72 | +$(function (){ |
| 73 | + $('.table').DataTable({ |
| 74 | + serverSide: true, |
| 75 | + processing: true, |
| 76 | + ajax: { |
| 77 | + url: window.location, |
| 78 | + type: 'GET', |
| 79 | + dataSrc: function (data) { |
| 80 | + return JSON.parse(atob(data.data)); |
| 81 | + } |
| 82 | + }, |
| 83 | + columns: [ |
| 84 | + {data: 'id'}, |
| 85 | + {data: 'name'}, |
| 86 | + {data: 'email'}, |
| 87 | + ], |
| 88 | + }); |
| 89 | +}); |
| 90 | +``` |
| 91 | +In this example, the UserController utilizes the SSP trait to process data for the User model according to the parameters specified in the request. |
| 92 | + |
| 93 | +## Configuration |
| 94 | +No additional configuration is required to start using SSP-INIT, as it uses Laravel's default configurations. |
| 95 | + |
| 96 | +## Support |
| 97 | +If you are having issues, please let us know by [submitting an issue on GitHub.](https://github.com/mrkacmaz/laravel-ssp/issues) |
| 98 | + |
| 99 | +## License |
| 100 | +This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/MrKacmaz/laravel-ssp/blob/master/LICENSE) file for details. |
| 101 | + |
0 commit comments