feature/create-migration-and-crud-api
This commit is contained in:
56
app/Http/Controllers/Api/UmkmController.php
Normal file
56
app/Http/Controllers/Api/UmkmController.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Models\Umkm;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\UmkmRequest;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Resources\UmkmResource;
|
||||
|
||||
class UmkmController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$umkms = Umkm::paginate();
|
||||
|
||||
return UmkmResource::collection($umkms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(UmkmRequest $request): Umkm
|
||||
{
|
||||
return Umkm::create($request->validated());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Umkm $umkm): Umkm
|
||||
{
|
||||
return $umkm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UmkmRequest $request, Umkm $umkm): Umkm
|
||||
{
|
||||
$umkm->update($request->validated());
|
||||
|
||||
return $umkm;
|
||||
}
|
||||
|
||||
public function destroy(Umkm $umkm): Response
|
||||
{
|
||||
$umkm->delete();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
44
app/Http/Requests/UmkmRequest.php
Normal file
44
app/Http/Requests/UmkmRequest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UmkmRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'business_name' => 'required|string',
|
||||
'business_address' => 'required|string',
|
||||
'business_desc' => 'required|string',
|
||||
'business_contact' => 'required|string',
|
||||
'business_id_number' => 'string',
|
||||
'business_scale_id' => 'required',
|
||||
'owner_id' => 'required|string',
|
||||
'owner_name' => 'required|string',
|
||||
'owner_address' => 'required|string',
|
||||
'owner_contact' => 'required|string',
|
||||
'business_type' => 'required|string',
|
||||
'business_form' => 'required|string',
|
||||
'revenue' => 'required',
|
||||
'village_code' => 'required|string',
|
||||
'distric_code' => 'required',
|
||||
'number_of_employee' => 'required',
|
||||
'permit_status_id' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
19
app/Http/Resources/UmkmResource.php
Normal file
19
app/Http/Resources/UmkmResource.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UmkmResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return parent::toArray($request);
|
||||
}
|
||||
}
|
||||
48
app/Models/Umkm.php
Normal file
48
app/Models/Umkm.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* Class Umkm
|
||||
*
|
||||
* @property $id
|
||||
* @property $created_at
|
||||
* @property $updated_at
|
||||
* @property $business_name
|
||||
* @property $business_address
|
||||
* @property $business_desc
|
||||
* @property $business_contact
|
||||
* @property $business_id_number
|
||||
* @property $business_scale_id
|
||||
* @property $owner_id
|
||||
* @property $owner_name
|
||||
* @property $owner_address
|
||||
* @property $owner_contact
|
||||
* @property $business_type
|
||||
* @property $business_form
|
||||
* @property $revenue
|
||||
* @property $village_code
|
||||
* @property $distric_code
|
||||
* @property $number_of_employee
|
||||
* @property $land_area
|
||||
* @property $permit_status_id
|
||||
*
|
||||
* @package App
|
||||
* @mixin \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
class Umkm extends Model
|
||||
{
|
||||
|
||||
protected $perPage = 20;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = ['business_name', 'business_address', 'business_desc', 'business_contact', 'business_id_number', 'business_scale_id', 'owner_id', 'owner_name', 'owner_address', 'owner_contact', 'business_type', 'business_form', 'revenue', 'village_code', 'distric_code', 'number_of_employee', 'land_area', 'permit_status_id'];
|
||||
|
||||
|
||||
}
|
||||
46
database/migrations/2025_02_12_083512_create_table_umkm.php
Normal file
46
database/migrations/2025_02_12_083512_create_table_umkm.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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('umkm', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
|
||||
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
|
||||
$table->string('business_name');
|
||||
$table->string('business_address');
|
||||
$table->string('business_desc');
|
||||
$table->string('business_contact');
|
||||
$table->string('business_id_number')->nullable();
|
||||
$table->integer('business_scale_id');
|
||||
$table->string('owner_id');
|
||||
$table->string('owner_name');
|
||||
$table->string('owner_address');
|
||||
$table->string('owner_contact');
|
||||
$table->string('business_type');
|
||||
$table->string('business_form');
|
||||
$table->decimal('revenue');
|
||||
$table->string('village_code');
|
||||
$table->integer('distric_code');
|
||||
$table->integer('number_of_employee');
|
||||
$table->float('land_area')->nullable();
|
||||
$table->integer('permit_status_id');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('umkm');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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('business_scale', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
|
||||
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
|
||||
$table->string('business_scale');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('business_scale');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
<?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('permit_status', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamp('created_at')->default(DB::raw('CURRENT_TIMESTAMP'));
|
||||
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
|
||||
$table->string('permit_status');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('permit_status');
|
||||
}
|
||||
};
|
||||
22
database/seeders/BusinessScaleSeeder.php
Normal file
22
database/seeders/BusinessScaleSeeder.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class BusinessScaleSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('business_scale')->insert([
|
||||
['business_scale' => 'Micro'],
|
||||
['business_scale' => 'Kecil'],
|
||||
['business_scale' => 'Menengah'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
22
database/seeders/PermitStatusSeeder.php
Normal file
22
database/seeders/PermitStatusSeeder.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PermitStatusSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('permit_status')->insert([
|
||||
['permit_status' => 'Not Registered'],
|
||||
['permit_status' => 'Registered'],
|
||||
['permit_status' => 'Application Process'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,9 @@ Route::group(['middleware' => 'auth:sanctum'], function (){
|
||||
Route::apiResource('advertisements', AdvertisementController::class);
|
||||
Route::get('/combobox/search-options', [AdvertisementController::class, 'searchOptionsInAdvertisements']);
|
||||
Route::post('/advertisements/import', [AdvertisementController::class, 'importFromFile']);
|
||||
|
||||
// route
|
||||
Route::apiResource('umkms', UmkmController::class);
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user