petani dan lahan
This commit is contained in:
@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use App\Models\Wilayah\Provinsi;
|
||||
use App\Models\Pertanian\Petani;
|
||||
@@ -75,12 +76,28 @@ class PetaniController extends Controller
|
||||
//'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'],
|
||||
'file_ktp' => ['nullable', 'image', 'mimes:jpeg,jpg,png', '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'],
|
||||
'file_kk' => ['nullable', 'image', 'mimes:jpeg,jpg,png', 'max:2048'],
|
||||
'foto' => ['nullable', 'image', 'mimes:jpeg,jpg,png', 'max:2048'],
|
||||
'nomor_telepon' => ['nullable', 'numeric', 'max:20'],
|
||||
]);
|
||||
|
||||
if ($request->hasFile('file_ktp')) {
|
||||
$file_ktp = $request->file('file_ktp');
|
||||
$validatedData['path_ktp'] = $file_ktp->store('petani/ktp');
|
||||
$validatedData['file_ktp'] = $file_ktp->getClientOriginalName();
|
||||
}
|
||||
if ($request->hasFile('file_kk')) {
|
||||
$file_kk = $request->file('file_kk');
|
||||
$validatedData['path_kk'] = $file_kk->store('petani/kk');
|
||||
$validatedData['file_kk'] = $file_kk->getClientOriginalName();
|
||||
}
|
||||
if ($request->hasFile('foto')) {
|
||||
$file_foto = $request->file('foto');
|
||||
$validatedData['foto'] = $file_foto->store('petani/foto');
|
||||
}
|
||||
|
||||
Petani::create([...$validatedData,
|
||||
'uid' => 'PTN-'. strtoupper(Str::random(10)),
|
||||
'created_by' => auth()->id(),
|
||||
@@ -145,8 +162,24 @@ class PetaniController extends Controller
|
||||
'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'],
|
||||
'nomor_telepon' => ['nullable', 'numeric', 'max:20'],
|
||||
]);
|
||||
|
||||
if ($request->hasFile('file_ktp')) {
|
||||
$file_ktp = $request->file('file_ktp');
|
||||
$validatedData['path_ktp'] = $file_ktp->store('petani/ktp');
|
||||
$validatedData['file_ktp'] = $file_ktp->getClientOriginalName();
|
||||
}
|
||||
if ($request->hasFile('file_kk')) {
|
||||
$file_kk = $request->file('file_kk');
|
||||
$validatedData['path_kk'] = $file_kk->store('petani/kk');
|
||||
$validatedData['file_kk'] = $file_kk->getClientOriginalName();
|
||||
}
|
||||
if ($request->hasFile('foto')) {
|
||||
$file_foto = $request->file('foto');
|
||||
$validatedData['foto'] = $file_foto->store('petani/foto');
|
||||
}
|
||||
|
||||
$petani->update([...$validatedData,
|
||||
'updated_by' => auth()->id()]);
|
||||
|
||||
@@ -160,4 +193,33 @@ class PetaniController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function showImage(string $id, string $field)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$petani = Petani::findOrFail($id);
|
||||
|
||||
switch ($field) {
|
||||
case 'ktp':
|
||||
$filePath = $petani->path_ktp;
|
||||
break;
|
||||
case 'kk':
|
||||
$filePath = $petani->path_kk;
|
||||
break;
|
||||
case 'foto':
|
||||
$filePath = $petani->foto;
|
||||
break;
|
||||
default:
|
||||
abort(404);
|
||||
}
|
||||
|
||||
if (!$filePath || !\Storage::exists($filePath)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return Storage::disk('local')->response($filePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ class PetaniLahanController extends Controller
|
||||
$petani = Petani::findOrFail($petaniId);
|
||||
|
||||
$lahan = Lahan::where('petani_id', $petaniId)
|
||||
->orderBy('created_at', 'desc')
|
||||
->orderBy('id', 'asc')
|
||||
->get();
|
||||
|
||||
$provinsi = Provinsi::orderBy('kode', 'asc')->get();
|
||||
@@ -171,9 +171,6 @@ class PetaniLahanController extends Controller
|
||||
return view('produktivitas.petani.lahan.edit', compact('lahan', 'lahanSelected', 'petani', 'komoditas', 'provinsi'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $petaniId, string $id)
|
||||
{
|
||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||
|
||||
Reference in New Issue
Block a user