style updates
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
<?php
|
||||
|
||||
return ['name' => 'Locations'];
|
||||
|
||||
@@ -1,3 +1,34 @@
|
||||
<?php
|
||||
use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema;
|
||||
return new class extends Migration { public function up(): void { Schema::create('locations',function(Blueprint $t): void{$t->id();$t->string('name');$t->string('slug')->unique();$t->string('type')->default('office');$t->text('address')->nullable();$t->string('postcode')->nullable();$t->string('country')->nullable();$t->string('phone')->nullable();$t->string('email')->nullable();$t->decimal('latitude',10,7)->nullable();$t->decimal('longitude',10,7)->nullable();$t->json('opening_hours')->nullable();$t->boolean('is_active')->default(true);$t->unsignedInteger('sort_order')->default(0);$t->timestamps();}); } public function down(): void { Schema::dropIfExists('locations'); } };
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('locations', function (Blueprint $t): void {
|
||||
$t->id();
|
||||
$t->string('name');
|
||||
$t->string('slug')->unique();
|
||||
$t->string('type')->default('office');
|
||||
$t->text('address')->nullable();
|
||||
$t->string('postcode')->nullable();
|
||||
$t->string('country')->nullable();
|
||||
$t->string('phone')->nullable();
|
||||
$t->string('email')->nullable();
|
||||
$t->decimal('latitude', 10, 7)->nullable();
|
||||
$t->decimal('longitude', 10, 7)->nullable();
|
||||
$t->json('opening_hours')->nullable();
|
||||
$t->boolean('is_active')->default(true);
|
||||
$t->unsignedInteger('sort_order')->default(0);
|
||||
$t->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('locations');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,31 @@
|
||||
<?php
|
||||
namespace Modules\Locations\Http\Controllers; use App\Http\Controllers\Controller; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\View\View; use Modules\Locations\Models\Location;
|
||||
final class LocationController extends Controller { public function index(): View { return view('locations::admin.index',['locations'=>Location::orderBy('sort_order')->orderBy('name')->paginate(25)]); } public function store(Request $r): RedirectResponse { Location::create($r->validate(['name'=>['required','string','max:255'],'slug'=>['required','string','max:255','unique:locations,slug'],'type'=>['required','in:office,store,warehouse,venue,service'],'address'=>['nullable','string'],'postcode'=>['nullable','string','max:30'],'country'=>['nullable','string','max:120'],'phone'=>['nullable','string','max:80'],'email'=>['nullable','email','max:255'],'latitude'=>['nullable','numeric','between:-90,90'],'longitude'=>['nullable','numeric','between:-180,180'],'sort_order'=>['nullable','integer','min:0']])+['is_active'=>$r->boolean('is_active',true)]); return back()->with('status','Location created.'); } public function destroy(Location $location): RedirectResponse { $location->delete(); return back()->with('status','Location deleted.'); } }
|
||||
|
||||
namespace Modules\Locations\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Modules\Locations\Models\Location;
|
||||
|
||||
final class LocationController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
return view('locations::admin.index', ['locations' => Location::orderBy('sort_order')->orderBy('name')->paginate(25)]);
|
||||
}
|
||||
|
||||
public function store(Request $r): RedirectResponse
|
||||
{
|
||||
Location::create($r->validate(['name' => ['required', 'string', 'max:255'], 'slug' => ['required', 'string', 'max:255', 'unique:locations,slug'], 'type' => ['required', 'in:office,store,warehouse,venue,service'], 'address' => ['nullable', 'string'], 'postcode' => ['nullable', 'string', 'max:30'], 'country' => ['nullable', 'string', 'max:120'], 'phone' => ['nullable', 'string', 'max:80'], 'email' => ['nullable', 'email', 'max:255'], 'latitude' => ['nullable', 'numeric', 'between:-90,90'], 'longitude' => ['nullable', 'numeric', 'between:-180,180'], 'sort_order' => ['nullable', 'integer', 'min:0']]) + ['is_active' => $r->boolean('is_active', true)]);
|
||||
|
||||
return back()->with('status', 'Location created.');
|
||||
}
|
||||
|
||||
public function destroy(Location $location): RedirectResponse
|
||||
{
|
||||
$location->delete();
|
||||
|
||||
return back()->with('status', 'Location deleted.');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,15 @@
|
||||
<?php
|
||||
namespace Modules\Locations\Models; use Illuminate\Database\Eloquent\Model;
|
||||
final class Location extends Model { protected $fillable=['name','slug','type','address','postcode','country','phone','email','latitude','longitude','opening_hours','is_active','sort_order']; protected function casts(): array { return ['latitude'=>'decimal:7','longitude'=>'decimal:7','opening_hours'=>'array','is_active'=>'boolean']; } }
|
||||
|
||||
namespace Modules\Locations\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
final class Location extends Model
|
||||
{
|
||||
protected $fillable = ['name', 'slug', 'type', 'address', 'postcode', 'country', 'phone', 'email', 'latitude', 'longitude', 'opening_hours', 'is_active', 'sort_order'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return ['latitude' => 'decimal:7', 'longitude' => 'decimal:7', 'opening_hours' => 'array', 'is_active' => 'boolean'];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Locations\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
final class LocationsServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
@@ -8,6 +11,7 @@ final class LocationsServiceProvider extends ServiceProvider
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->mergeConfigFrom(module_path('Locations', 'Config/config.php'), 'locations');
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$this->loadMigrationsFrom(module_path('Locations', 'Database/Migrations'));
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Locations\Providers;
|
||||
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
final class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot(): void
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
<?php
|
||||
use Illuminate\Support\Facades\Route; use Modules\Locations\Http\Controllers\LocationController;
|
||||
Route::middleware(['auth','verified'])->prefix('administration/locations')->name('administration.locations.')->group(function(): void { Route::get('/',[LocationController::class,'index'])->name('index'); Route::post('/',[LocationController::class,'store'])->name('store'); Route::delete('/{location}',[LocationController::class,'destroy'])->name('destroy'); });
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Locations\Http\Controllers\LocationController;
|
||||
|
||||
Route::middleware(['auth', 'verified'])->prefix('administration/locations')->name('administration.locations.')->group(function (): void {
|
||||
Route::get('/', [LocationController::class, 'index'])->name('index');
|
||||
Route::post('/', [LocationController::class, 'store'])->name('store');
|
||||
Route::delete('/{location}', [LocationController::class, 'destroy'])->name('destroy');
|
||||
});
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Locations\Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
final class ModuleBootTest extends TestCase
|
||||
{
|
||||
public function test_module_configuration_is_available(): void
|
||||
|
||||
Reference in New Issue
Block a user