164 lines
4.2 KiB
PHP
164 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\FrontOffice;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\TransaksiParkir;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class FrontOfficeController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
return view ('frontoffice.index');
|
|
}
|
|
|
|
public function search(Request $request)
|
|
{
|
|
// Log::info($request->all());
|
|
$keyword = $request->q;
|
|
Log::info($keyword);
|
|
|
|
if (!$keyword) {
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => 'Input kosong'
|
|
]);
|
|
}
|
|
|
|
// $data = TransaksiParkir::where('no_pol', $keyword)
|
|
$data = DB::table('transaksi_parkir')->where('no_pol', $keyword)
|
|
->select(DB::raw(
|
|
'CAST(id AS TEXT) as id, no_pol, waktu_masuk, id_kendaraan, pic_body_masuk'
|
|
))
|
|
// ->where('status', 1)
|
|
// ->orWhere('no_pol', $keyword)
|
|
->orderByDesc('waktu_masuk')
|
|
->first();
|
|
|
|
if (!empty($data->pic_body_masuk) && is_resource($data->pic_body_masuk)) {
|
|
$data->pic_body_masuk = base64_encode(stream_get_contents($data->pic_body_masuk)) ?? 'Not Image';
|
|
} else {
|
|
$data->pic_body_masuk = 'No Image';
|
|
}
|
|
// $pic_body_masuk = (string) $data->pic_body_masuk;
|
|
|
|
// $data->pic_body_masuk_base64 = $data->pic_body_masuk
|
|
// ? 'data:image/jpeg;base64,' . base64_encode($pic_body_masuk )
|
|
// : null;
|
|
|
|
// Log::info($data);
|
|
|
|
if (!$data) {
|
|
return response()->json([
|
|
'status' => false,
|
|
'message' => 'Data tidak ditemukan'
|
|
]);
|
|
}
|
|
|
|
return response()->json([
|
|
'status' => true,
|
|
// 'data' => $data
|
|
'data' => [
|
|
'id' => (string) $data->id,
|
|
'no_pol' => $data->no_pol,
|
|
'waktu_masuk' => $data->waktu_masuk,
|
|
'vehicle_capt' => $data->pic_body_masuk
|
|
]
|
|
]);
|
|
}
|
|
|
|
public function image($id)
|
|
{
|
|
$picture = TransaksiParkir::select('pic_body_masuk')->where('no_pol', $id)
|
|
->where('status', 1)
|
|
->orderByDesc('waktu_masuk')
|
|
->first();
|
|
|
|
// return response($picture->pic_body_masuk)
|
|
// ->header('Content-Type', 'image/jpeg');
|
|
|
|
// ❌ kalau tidak ada data
|
|
if (!$picture || !$picture->pic_body_masuk) {
|
|
return response()->file(public_path('images/no-image.jpg'));
|
|
}
|
|
|
|
return response($picture->pic_body_masuk)
|
|
->header('Content-Type', 'image/jpeg')
|
|
->header('Cache-Control', 'public, max-age=86400'); // cache 1 hari
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
Log::info('Method Store : ' . json_encode($request->all()));
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
Log::info($request->all());
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|