Installation Add the bundle to your Laravel project via Composer:
composer require bulutyazilim/location-bundle
Publish the migrations and config:
php artisan vendor:publish --provider="Bulutyazilim\LocationBundle\LocationBundleServiceProvider"
Run migrations:
php artisan migrate
First Use Case
Access the Country and City models directly:
use Bulutyazilim\LocationBundle\Entity\Country;
use Bulutyazilim\LocationBundle\Entity\City;
$countries = Country::all();
$cities = City::where('country_id', 1)->get();
Where to Look First
src/Entity/Country.php and src/Entity/City.php for model structure.database/migrations/ for schema details.LocationBundleServiceProvider.php for bootstrapping logic.Data Retrieval Fetch countries with eager-loaded cities:
$countries = Country::with('cities')->get();
Form Integration Use in Laravel Collective or Livewire forms:
// Example for Laravel Collective
<select name="country_id">
@foreach(Country::all() as $country)
<option value="{{ $country->id }}">{{ $country->name }}</option>
@endforeach
</select>
API Responses Return structured location data:
return response()->json([
'countries' => Country::with('cities')->get()
]);
Validation: Use custom rules for country/city IDs:
use Illuminate\Validation\Rule;
$validator = Validator::make($request->all(), [
'country_id' => ['required', Rule::exists('countries', 'id')],
'city_id' => ['required', Rule::exists('cities', 'id')->where('country_id', $request->country_id)],
]);
Caching: Cache country/city lists if static:
$countries = Cache::remember('location.countries', 60*24, function() {
return Country::all();
});
Localization: Extend entities for multilingual support:
// Add translatable fields (e.g., name_en, name_tr) and handle in models.
Outdated Codebase
created_at vs. date_created).Missing Features
Country::where('name', 'like', '%USA%')->get();
spatie/laravel-geolocation) if needed.Database Schema
cities table has country_id foreign key. Verify migrations match your needs.LocationBundleServiceProvider is registered in config/app.php.order as a column name). Rename if conflicts arise.Custom Fields Extend entities via traits or inheritance:
namespace App\Models;
use Bulutyazilim\LocationBundle\Entity\Country as BaseCountry;
class Country extends BaseCountry {
protected $table = 'custom_countries';
}
API Resources Create custom resources for API responses:
php artisan make:resource CountryResource
Seeding
Seed initial data via DatabaseSeeder:
$this->call([
Bulutyazilim\LocationBundle\Database\Seeders\CountrySeeder::class,
Bulutyazilim\LocationBundle\Database\Seeders\CitySeeder::class,
]);
countries, cities). Override in AppServiceProvider:
Country::setTable('my_custom_countries');
How can I help you explore Laravel packages today?