2e2b42f96b
- Add user_id FK (nullable) to rumah_ibadah for ownership tracking - IbadahController: set user_id on store; enforce ownership on update/destroy - Add edit modals to map and data views (ibadah + miskin) - Popup and table row Edit buttons with per-record ownership check - 7 new tests covering ownership and full-field updates - Fix ExampleTest for auth-protected routes - Fix UserFactory missing email_verified_at column - Mark Plan 2 complete in missing_features.md; update README Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
72 lines
2.2 KiB
PHP
72 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\RumahIbadah;
|
|
use Illuminate\Http\Request;
|
|
|
|
class IbadahController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return response()->json(RumahIbadah::all());
|
|
}
|
|
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
'nama' => 'required|string',
|
|
'jenis' => 'nullable|string',
|
|
'alamat' => 'nullable|string',
|
|
'latitude' => 'required|numeric',
|
|
'longitude' => 'required|numeric',
|
|
'radius' => 'nullable|integer',
|
|
'jumlah_jemaah' => 'nullable|integer',
|
|
'pengurus' => 'nullable|string',
|
|
'telepon' => 'nullable|string',
|
|
'keterangan' => 'nullable|string',
|
|
]);
|
|
|
|
$validated['user_id'] = auth()->id();
|
|
$ibadah = RumahIbadah::create($validated);
|
|
return response()->json(['success' => true, 'data' => $ibadah]);
|
|
}
|
|
|
|
public function update(Request $request, $id)
|
|
{
|
|
$ibadah = RumahIbadah::findOrFail($id);
|
|
|
|
if (!auth()->user()->hasRole('administrator') && $ibadah->user_id !== auth()->id()) {
|
|
return response()->json(['message' => 'Tidak diizinkan mengubah data ini.'], 403);
|
|
}
|
|
|
|
$validated = $request->validate([
|
|
'nama' => 'required|string',
|
|
'jenis' => 'nullable|string',
|
|
'alamat' => 'nullable|string',
|
|
'latitude' => 'required|numeric',
|
|
'longitude' => 'required|numeric',
|
|
'radius' => 'required|integer',
|
|
'jumlah_jemaah' => 'nullable|integer',
|
|
'pengurus' => 'nullable|string',
|
|
'telepon' => 'nullable|string',
|
|
'keterangan' => 'nullable|string',
|
|
]);
|
|
|
|
$ibadah->update($validated);
|
|
return response()->json(['success' => true, 'data' => $ibadah]);
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
$ibadah = RumahIbadah::findOrFail($id);
|
|
|
|
if (!auth()->user()->hasRole('administrator') && $ibadah->user_id !== auth()->id()) {
|
|
return response()->json(['message' => 'Tidak diizinkan menghapus data ini.'], 403);
|
|
}
|
|
|
|
$ibadah->delete();
|
|
return response()->json(['success' => true]);
|
|
}
|
|
}
|