A lightweight, production-ready pattern for binding MySQL data to a Syncfusion JavaScript Grid via Laravel API. The sample supports complete CRUD (Insert, Read, Update, Delete), server-side filtering, searching, sorting, and paging using DataManager + UrlAdaptor with Laravel Eloquent models and Blade templates.
- MySQL ↔ Laravel: Native PDO MySQL driver + migrations-driven schema
- Syncfusion JavaScript Grid: Built-in paging, sorting, filtering, searching, and editing via CDN
- Full CRUD: Add, edit, and delete directly from the grid
- Server-side Data Operations: Read/search/filter/sort/page handled by Laravel API
- Blade Templates: Server-side templating with Syncfusion components
- RESTful API: JSON responses with pagination metadata
| Requirement | Version | Purpose |
|---|---|---|
| PHP | 8.1 or higher | Laravel runtime environment |
| Laravel | 10.x or 11.x | PHP web application framework |
| Composer | 2.0+ | PHP package manager for dependencies |
| MySQL | 8.0 or higher | Database server |
git clone https://github.com/SyncfusionExamples/syncfusion-grid-component-in-php-laravel
cd syncfusion-grid-component-in-laravelcomposer installCreate a new MySQL database:
mysql -u root -p
CREATE DATABASE students_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
EXIT;Update .env file with your database credentials:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=students_db
DB_USERNAME=root
DB_PASSWORD=your_passwordphp artisan migrate:fresh --seedThis creates the students table and seeds 1000 sample records.
php artisan serveAccess the application at http://localhost:8000
| File/Folder | Purpose |
|---|---|
app/Models/Student.php |
Eloquent model for student data |
app/Http/Controllers/ServerController.php |
API controller handling CRUD operations |
database/migrations/ |
Database schema definitions |
database/seeders/DatabaseSeeder.php |
Sample data seeder (1000 records) |
routes/api.php |
API routes for DataManager |
routes/web.php |
Web routes for Blade templates |
resources/views/grid.blade.php |
Blade template with Syncfusion Grid |
config/cors.php |
CORS configuration |
All endpoints receive POST requests and return JSON with result and count fields:
| Endpoint | Purpose |
|---|---|
POST /api/read |
Fetch records with paging, filtering, sorting, and searching |
POST /api/insert |
Insert new record |
POST /api/update |
Update existing record |
POST /api/remove |
Delete record |
Example Response:
{
"result": [
{ "id": 1, "FirstName": "John", "LastName": "Doe", "Email": "john@example.com", "Course": "Banking" }
],
"count": 1000
}- Click Add in the grid toolbar
- Fill out fields (First Name, Last Name, Email, Course)
- Click Save → Creates record via
POST /api/insert
- Select a row → Click Edit
- Modify fields → Click Update
- Record updated via
POST /api/update
- Select a row → Click Delete
- Confirm deletion → Record deleted via
POST /api/remove
- Use the Search box to match across columns
- Use column filter icons for specific filtering
- Click column headers to sort (server-side sorting)
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=students_db
DB_USERNAME=root
DB_PASSWORD=your_password'allowed_origins' => ['*'], // For development only
'allowed_methods' => ['*'],
'allowed_headers' => ['*'],For production, replace '*' with your actual domain.
| Issue | Solution |
|---|---|
| MySQL Connection Error | Verify MySQL is running, check .env credentials, ensure students_db exists |
| CORS Blocked | Enable CORS middleware, set 'allowed_origins' => ['*'] in config/cors.php |
| Grid Not Loading Data | Check browser Network tab for API response, verify DataManager URLs match routes |
| Migration Failed | Run php artisan migrate:fresh to reset, check SQL syntax in migrations |
| Blade Template Not Found | Verify resources/views/grid.blade.php exists, check web route in routes/web.php |
| Syncfusion CDN Not Loading | Check browser console, ensure internet connection, verify CDN URLs are correct |
| Validation/422 Errors | Ensure required fields are provided, verify field names match database columns |
- Backend: Laravel 10/11, PHP 8.1+
- Database: MySQL 8.0+
- Frontend: Vanilla JavaScript + Syncfusion Grid (CDN)
- Templates: Blade (Laravel)
- API: RESTful JSON endpoints
- Syncfusion JavaScript Grid Documentation
- Syncfusion Grid + Laravel Integration
- Laravel Documentation
- Laravel Eloquent ORM