amranidev/ajaxis
Ajaxis is a Laravel package for AJAX-based CRUD using Bootstrap or Materialize modals. It can auto-generate form inputs (text, radio, checkbox, file, etc.) and lets you manage inputs, APIs, and CRUD actions through a model controller with a single reusable modal block.
Installation
composer require amranidev/ajaxis
Publish the config file (if needed):
php artisan vendor:publish --provider="Ajaxis\AjaxisServiceProvider"
Basic Configuration
Edit config/ajaxis.php to define your CRUD routes and views:
'crud' => [
'users' => [
'model' => 'App\Models\User',
'view' => 'users.index',
'routes' => [
'index' => 'users',
'store' => 'users.store',
'update' => 'users.update',
'destroy' => 'users.destroy',
],
],
],
First Use Case: Quick CRUD AJAX Endpoint Define a controller method to handle AJAX requests:
use Ajaxis\Ajaxis;
public function index(Ajaxis $ajaxis)
{
return $ajaxis->get('users')->table();
}
Add the route in routes/web.php:
Route::get('/users', 'UserController@index');
Frontend Integration Include the package’s JS/CSS in your blade view:
@include('ajaxis::scripts')
Use the provided table helper:
<table class="ajaxis-table" data-url="{{ route('users.index') }}">
<thead>
<tr><th>ID</th><th>Name</th><th>Actions</th></tr>
</thead>
</table>
Dynamic Table Rendering
Use Ajaxis to fetch and render data dynamically:
public function index(Ajaxis $ajaxis)
{
return $ajaxis->get('users')
->select(['id', 'name', 'email'])
->table(['id', 'name', 'email'], ['edit', 'delete']);
}
['edit', 'delete']).Form Handling (Create/Update)
For AJAX forms, use the form() method:
public function create(Ajaxis $ajaxis)
{
return $ajaxis->form('users.store', [
'name' => 'text',
'email' => 'email',
]);
}
Custom Views Override default views by publishing assets:
php artisan vendor:publish --tag=ajaxis-views
Place custom views in resources/views/vendor/ajaxis/.
Middleware Integration
Protect routes with middleware (e.g., auth):
Route::middleware('auth')->group(function () {
Route::get('/users', 'UserController@index');
});
Pagination
Enable pagination in the get() method:
return $ajaxis->get('users')->paginate(10)->table();
return $ajaxis->get('users')->json();
ajaxis.* events (e.g., ajaxis.beforeRender).resources/lang/vendor/ajaxis.Outdated Package
@ajaxis).CSRF Token Mismatch Ensure AJAX requests include the CSRF token:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
Route Caching Conflicts Clear route cache if routes aren’t recognized:
php artisan route:clear
View Override Pitfalls
resources/views/vendor/ajaxis/table.blade.php).@include('ajaxis::scripts') breaks AJAX functionality.Model Binding Issues
Ensure your model uses Laravel’s standard conventions (e.g., App\Models\User).
Custom primary keys may require explicit configuration:
$ajaxis->get('users')->primaryKey('user_id');
Check Network Requests Use browser dev tools to verify AJAX payloads/responses. Common issues:
Log Ajaxis Events
Add debug logs in app/Providers/AjaxisServiceProvider.php:
Ajaxis::macro('debug', function () {
\Log::debug('Ajaxis request:', $this->request->all());
});
Validate JSON Responses Ensure the package returns valid JSON for AJAX:
return response()->json(['success' => false, 'errors' => $validator->errors()]);
Custom Directives
Extend Blade directives (e.g., @ajaxisForm):
Blade::directive('ajaxisForm', function ($expression) {
return "<?php echo Ajaxis::form($expression); ?>";
});
Hooks for Pre/Post Processing
Use Laravel’s ModelObserver or Ajaxis macros:
Ajaxis::macro('customAction', function ($action) {
return $this->extend(function ($response) use ($action) {
$response['custom'] = "Processed via {$action}";
return $response;
});
});
Database Observers
Trigger actions on model events (e.g., saved):
class UserObserver {
public function saved(User $user) {
event(new UserSaved($user));
}
}
API Integration Combine with Laravel Sanctum/Passport for authenticated AJAX:
$.ajax({
headers: {
'Authorization': 'Bearer ' + token,
'X-CSRF-TOKEN': token
}
});
$ajaxis->get('users')->with('roles')->table();
return Cache::remember('users.list', now()->addHours(1), function () {
return $ajaxis->get('users')->table();
});
How can I help you explore Laravel packages today?