partial update spatial plannings crud

This commit is contained in:
arifal
2025-02-19 12:08:18 +07:00
parent e8da7193ef
commit 54146c8c08
6 changed files with 217 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\SpatialPlanning;
use Illuminate\Http\Request;
class SpatialPlanningsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$query = SpatialPlanning::query()->orderBy('id', 'desc');
if ($request->has("search") &&!empty($request->get("search"))) {
$query = $query->where("name", "LIKE", "%{$request->get("search")}%")
->orWhere("nomor", "LIKE", "%{$request->get("search")}%");
}
$query = $query->paginate();
return response()->json($query);
}
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
try{
SpatialPlanning::destroy($id);
return response()->json([
'message' => 'Data berhasil dihapus'
], 200);
}catch(\Exception $e){
return response()->json([
'error' => $e->getMessage()
], 500);
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SpatialPlanningsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('spatial-plannings.index');
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('spatial-plannings.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
return view('spatial-plannings.update');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class SpatialPlanningsRequest 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 [
'name' => ['required','string','max:255'],
'kbli' => ['required','string','max:255'],
'kegiatan' => ['required','string'],
'luas' => ['required','numeric','regex:/^\d{1,16}(\.\d{1,2})?$/'],
'lokasi' => ['required','string'],
'nomor' => ['required','string','max:255',Rule::unique('spatial_plannings')->ignore($this->id)],
'tanggal' => ['required','date'],
];
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class SpatialPlanning extends Model
{
protected $table = "spatial_plannings";
protected $fillable = [
'name',
'kbli',
'kegiatan',
'luas',
'lokasi',
'nomor',
'sp_date'
];
}

View File

@@ -0,0 +1,34 @@
<?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('spatial_plannings', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('kbli');
$table->text('kegiatan');
$table->decimal('luas',18,2);
$table->text('lokasi');
$table->string('nomor')->unique();
$table->date('sp_date');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('spatial_plannings');
}
};

View File

@@ -0,0 +1,3 @@
<div>
<!-- The whole future lies in uncertainty: live immediately. - Seneca -->
</div>