This repository accompanies the blog post on ItStuffSolutions: Laravel 12 Select2 Ajax Autocomplete Search Example
It shows how to implement a dynamic, searchable dropdown using Select2 JS and Ajax in a Laravel 12 application.
- Live Ajax‐powered dropdown search with Select2.
- Real‐time server filtering for large datasets.
- Built with Laravel 12, jQuery, Select2 v4+ and Bootstrap styling.
- Easy to integrate or adapt in your own Laravel project.
- PHP >= 8.1 (compatible with Laravel 12)
- Composer
- A fresh (or existing) Laravel 12 application
- MySQL / SQLite / other supported DB configured
- Node & npm (optional, if you compile frontend assets)
- jQuery and Select2 included in your view
# Clone the repo (or create your project directory)
git clone <your-repo-url>
cd <your-repo-folder>
# Install PHP dependencies
composer install
# Copy environment file and set up your DB credentials
cp .env.example .env
# Update .env:
# DB_HOST=...
# DB_DATABASE=...
# DB_USERNAME=...
# DB_PASSWORD=...
# Generate Laravel application key
php artisan key:generate
# Run migrations (and optionally seed dummy data)
php artisan migrate
# (Optional) Install Node dependencies & compile assets
npm install
npm run dev
# Serve the app locally
php artisan serve