141 lines
4.2 KiB
PHP
141 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
use App\Models\Laporan;
|
|
use App\Http\Requests\StoreLaporanRequest;
|
|
use App\Http\Requests\UpdateLaporanRequest;
|
|
use App\Models\Masyarakat;
|
|
use App\Models\Pelaku;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Redirect;
|
|
|
|
class LaporanController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$cekdata = Masyarakat::where('user_id', Auth::user()->id)->first();
|
|
if ($cekdata->jenis_kelamin == null || $cekdata->alamat == null || $cekdata->tempat_lahir == null || $cekdata->tanggal_lahir == null || $cekdata->nohp == null) {
|
|
return Redirect::route('masyarakat.create')->with('errorr', 'Lengkapi profil Anda terlebih dahulu sebelum mengirim laporan foto pelaku kejahatan');
|
|
} else {
|
|
$cekprofile = Masyarakat::where('user_id', Auth::user()->id)->first();
|
|
$user = User::where('id', Auth::user()->id)->first();
|
|
return view('client-side.laporan.lapor-pelaku', compact(['cekprofile', 'user']));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\StoreLaporanRequest $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(StoreLaporanRequest $request)
|
|
{
|
|
$request->validate([
|
|
'tanggal' => 'required',
|
|
'deskripsi' => 'required',
|
|
'gambar' => 'required|mimes:png,jpg,jpeg|max:2048',
|
|
]);
|
|
|
|
$data = $request->all();
|
|
|
|
$gambar = $data['gambar'];
|
|
$filename = strtolower('laporan-' . Auth::user()->name . '-' . time() . '-' . $gambar->getClientOriginalName());
|
|
$destinationPath = public_path('assets/images/laporan-masyarakat');
|
|
$gambar->move($destinationPath, $filename);
|
|
$data['gambar'] = strtolower('laporan-' . Auth::user()->name . '-' . time() . '-' . $gambar->getClientOriginalName());
|
|
|
|
Laporan::create($data);
|
|
|
|
return Redirect::route('laporan.index')->with('message', 'Berhasil mengirim laporan ke Admin Tectcrime. Terima kasih banyak atas bantuan laporan Anda. Semoga hari Anda menyenangkan.');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param \App\Models\Laporan $laporan
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Laporan $laporan)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param \App\Models\Laporan $laporan
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Laporan $laporan)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \App\Http\Requests\UpdateLaporanRequest $request
|
|
* @param \App\Models\Laporan $laporan
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(UpdateLaporanRequest $request, Laporan $laporan)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\Laporan $laporan
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Laporan $laporan)
|
|
{
|
|
//
|
|
}
|
|
|
|
|
|
// ? Function tambahan
|
|
|
|
public function laporanMasyarakat()
|
|
{
|
|
$data = Laporan::join('masyarakats', 'laporans.masyarakat_id', '=', 'masyarakats.id')->join('users', 'masyarakats.user_id', '=', 'users.id')->where('laporans.status', 'disetujui')->orderBy('laporans.created_at', 'desc')->select('*')->get();
|
|
return view('client-side.laporan.laporan-masyarakat', compact(['data']));
|
|
}
|
|
|
|
public function download($filename)
|
|
{
|
|
$file = public_path('assets/images/laporan-masyarakat/' . $filename);
|
|
|
|
if (file_exists($file)) {
|
|
return response()->download($file);
|
|
} else {
|
|
abort(404);
|
|
}
|
|
}
|
|
|
|
public function deteksiPelaku()
|
|
{
|
|
$data = Pelaku::all();
|
|
return view('client-side.laporan.deteksi-pelaku', compact(['data']));
|
|
}
|
|
}
|