petani
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Produktivitas;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use App\Models\Wilayah\Provinsi;
|
||||
use App\Models\Pertanian\Petani;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
|
||||
use App\Enums\Pendidikan;
|
||||
use App\Enums\Pekerjaan;
|
||||
use App\Enums\Pernikahan;
|
||||
|
||||
class PetaniController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
||||
|
||||
$query = Petani::with('desakelurahan')
|
||||
->orderBy('created_at', 'desc');
|
||||
|
||||
if ($request->search) {
|
||||
$query->where(function ($query) use ($request) {
|
||||
$query->where('nama', 'like', '%' . $request->search . '%')
|
||||
->orWhere('ktp', 'like', '%' . $request->search . '%');
|
||||
});
|
||||
}
|
||||
|
||||
$petani = $query->paginate($request->per_page ?? 10);
|
||||
|
||||
return view('produktivitas.petani.index', compact('petani', 'provinsi'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$pendidikan = Pendidikan::options();
|
||||
$pekerjaan = Pekerjaan::options();
|
||||
$pernikahan = Pernikahan::options();
|
||||
|
||||
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
||||
|
||||
return view('produktivitas.petani.add', compact('pendidikan', 'pekerjaan',
|
||||
'pernikahan', 'provinsi'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$validatedData = $request->validate([
|
||||
'nama' => ['required','string','max:255'],
|
||||
'jenis_kelamin' => ['required','boolean'],
|
||||
'tempat_lahir' => ['required','string','max:255'],
|
||||
'tanggal_lahir' => ['required','date'],
|
||||
'pendidikan_terakhir' => ['required', Rule::enum(Pendidikan::class)],
|
||||
'alamat' => ['required','string','max:500'],
|
||||
'desa_kelurahan_id' => ['required','exists:master_desa_kelurahan,id'],
|
||||
//'komoditas_id' => ['required','exists:master_komoditas,id'],
|
||||
'status_perkawinan' => ['required', Rule::enum(Pernikahan::class)],
|
||||
'ktp' => ['nullable', 'min:16', 'max:16'],
|
||||
'file_ktp' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'],
|
||||
'kk' => ['nullable', 'min:16', 'max:16'],
|
||||
'file_kk' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'],
|
||||
'foto' => ['nullable', 'file', 'mimes:jpeg,jpg,png', 'max:2048'],
|
||||
]);
|
||||
|
||||
Petani::create([...$validatedData,
|
||||
'uid' => 'PTN-'. strtoupper(Str::random(10)),
|
||||
'created_by' => auth()->id(),
|
||||
'updated_by' => auth()->id()]);
|
||||
|
||||
return redirect()->route('petani.index')->with('success', 'Data petani berhasil ditambahkan.');
|
||||
}
|
||||
|
||||
public function show(string $id)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$petani = Petani::findOrFail($id);
|
||||
|
||||
return view('produktivitas.petani.view', compact('petani'));
|
||||
}
|
||||
|
||||
|
||||
public function edit(string $id, Request $request)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$petani = Petani::findOrFail($id);
|
||||
|
||||
$pendidikan = Pendidikan::options();
|
||||
$pekerjaan = Pekerjaan::options();
|
||||
$pernikahan = Pernikahan::options();
|
||||
|
||||
$provinsi = Provinsi::all();
|
||||
|
||||
$section = $request->section ?? 'budidaya';
|
||||
|
||||
return view('produktivitas.petani.edit', compact('petani', 'pendidikan', 'pekerjaan',
|
||||
'pernikahan', 'provinsi', 'section'));
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$petani = Petani::findOrFail($id);
|
||||
|
||||
$validatedData = $request->validate([
|
||||
'nama' => ['required','string','max:255'],
|
||||
'jenis_kelamin' => ['required','boolean'],
|
||||
'tempat_lahir' => ['required','string','max:255'],
|
||||
'tanggal_lahir' => ['required','date'],
|
||||
'pendidikan_terakhir' => ['required', Rule::enum(Pendidikan::class)],
|
||||
'alamat' => ['required','string','max:500'],
|
||||
'desa_kelurahan_id' => ['required','exists:master_desa_kelurahan,id'],
|
||||
//'komoditas_id' => ['required','exists:master_komoditas,id'],
|
||||
'status_perkawinan' => ['required', Rule::enum(Pernikahan::class)],
|
||||
'ktp' => ['nullable', 'min:16', 'max:16'],
|
||||
'file_ktp' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'],
|
||||
'kk' => ['nullable', 'min:16', 'max:16'],
|
||||
'file_kk' => ['nullable', 'file', 'mimes:jpeg,jpg,png,pdf', 'max:2048'],
|
||||
'foto' => ['nullable', 'file', 'mimes:jpeg,jpg,png', 'max:2048'],
|
||||
]);
|
||||
|
||||
$petani->update([...$validatedData,
|
||||
'updated_by' => auth()->id()]);
|
||||
|
||||
return redirect()->route('petani.index')->with('success', 'Data petani berhasil diupdate.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Produktivitas;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
use App\Models\Pertanian\Petani;
|
||||
use App\Models\Pertanian\Lahan;
|
||||
use App\Models\Wilayah\DesaKelurahan;
|
||||
use App\Models\Wilayah\Provinsi;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
|
||||
class PetaniLahanController extends Controller
|
||||
{
|
||||
public function index($petaniId, Request $request)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$petani = Petani::findOrFail($petaniId);
|
||||
|
||||
$lahan = Lahan::where('petani_id', $petaniId)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate($request->per_page ?? 10);
|
||||
|
||||
return view('produktivitas.petani.lahan.index', compact('petani', 'lahan'));
|
||||
}
|
||||
|
||||
public function create($petaniId)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$petani = Petani::findOrFail($petaniId);
|
||||
|
||||
$lahan = Lahan::where('petani_id', $petaniId)
|
||||
->orderBy('created_at', 'desc')
|
||||
->paginate($request->per_page ?? 10);
|
||||
|
||||
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
||||
|
||||
$komoditas = Komoditas::all();
|
||||
|
||||
return view('produktivitas.petani.lahan.add', compact('petani', 'lahan', 'provinsi', 'komoditas'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ class Lahan extends Model
|
||||
'nama',
|
||||
'status_kepemilikan',
|
||||
'profile_id',
|
||||
'petani_id',
|
||||
'desa_kelurahan_id',
|
||||
'uid',
|
||||
'path',
|
||||
|
||||
Reference in New Issue
Block a user