install
This commit is contained in:
36
app/Modules/Province/Controllers/ProvinceController.php
Normal file
36
app/Modules/Province/Controllers/ProvinceController.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Modules\Province\Models\Province;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProvinceController extends Controller
|
||||
{
|
||||
/**
|
||||
* LIST provinces (etraplar)
|
||||
*/
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$request->validate([
|
||||
'groupBy' => ['nullable', 'string', 'in:region'],
|
||||
]);
|
||||
|
||||
$provinces = Province::query()
|
||||
->where('active', true)
|
||||
->get()
|
||||
->map(fn (Province $province) => [
|
||||
'id' => $province->id,
|
||||
'name' => $province->name,
|
||||
'region' => $province->region,
|
||||
]);
|
||||
|
||||
if ($request->filled('groupBy')) {
|
||||
$provinces = $provinces->groupBy('region');
|
||||
}
|
||||
|
||||
return response()->json($provinces);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('provinces', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('region');
|
||||
$table->json('name');
|
||||
$table->boolean('active')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('provinces');
|
||||
}
|
||||
};
|
||||
42
app/Modules/Province/Models/Province.php
Normal file
42
app/Modules/Province/Models/Province.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $region
|
||||
* @property array<string, string> $name
|
||||
* @property bool $active
|
||||
* @property \Illuminate\Support\Carbon $created_at
|
||||
* @property \Illuminate\Support\Carbon $updated_at
|
||||
*/
|
||||
class Province extends Model
|
||||
{
|
||||
use HasTranslations;
|
||||
|
||||
/**
|
||||
* Table name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'provinces';
|
||||
|
||||
/**
|
||||
* Translatable fieldsg
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public $translatable = ['name'];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'active' => 'boolean',
|
||||
];
|
||||
}
|
||||
64
app/Modules/Province/ProvinceModule.php
Normal file
64
app/Modules/Province/ProvinceModule.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province;
|
||||
|
||||
use App\Modules\Makeable;
|
||||
use App\Modules\ModuleContract;
|
||||
|
||||
class ProvinceModule implements ModuleContract
|
||||
{
|
||||
use Makeable;
|
||||
|
||||
/**
|
||||
* Module is enabled
|
||||
*/
|
||||
protected bool $enabled = true;
|
||||
|
||||
/**
|
||||
* Check if is module enabled
|
||||
*/
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return $this->enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable module
|
||||
*/
|
||||
public function disable(): void
|
||||
{
|
||||
$this->enabled = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable module
|
||||
*/
|
||||
public function enable(): void
|
||||
{
|
||||
$this->enabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if module has a filament resource
|
||||
*/
|
||||
public function hasFilamentResource(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer requirements
|
||||
*/
|
||||
public function getComposerRequirements(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get module composer suggestions
|
||||
*/
|
||||
public function getComposerSuggestions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
5
app/Modules/Province/Repositories/ProvinceRepository.php
Normal file
5
app/Modules/Province/Repositories/ProvinceRepository.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Province\Repositories;
|
||||
|
||||
class ProvinceRepository {}
|
||||
6
app/Modules/Province/Resources/Lang/tk/base.php
Normal file
6
app/Modules/Province/Resources/Lang/tk/base.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'Province' => 'Etrap',
|
||||
'Provinces' => 'Etraplar',
|
||||
];
|
||||
Reference in New Issue
Block a user