File manager - Edit - /home/asiatechinc/public_html/asiatech-websites/demo/Dynast/app/Http/Controllers/CheckInController.php
Back
<?php namespace App\Http\Controllers; use App\Models\CheckIn; use App\Traits\CommonFunctions; use App\Traits\ResponseAPI; use Exception; use Illuminate\Support\Facades\DB; use Yajra\DataTables\Facades\DataTables; use Illuminate\Http\Request; class CheckInController extends Controller { use CommonFunctions; use ResponseAPI; public function store(Request $request) { $checkIn = CheckIn::create([ "checkIn"=> $request->checkIn, "checkOut" => $request->checkOut , 'name' => $request->name, "phone_no" => $request->phone_no , 'ip_address' => $request->ip(), ]); return response()->json([ 'status' => true, 'success' => true, ], 200); } public function checkInPage(){ return view("Dashboard.Pages.checkInManagement"); } public function checkInDataTable(){ $query = CheckIn::select( DB::raw('DATE_FORMAT(CONVERT_TZ(checkIn, "+00:00", "+05:30"), "%W %M %e %Y %r") as checkIn_formatted'), DB::raw('DATE_FORMAT(CONVERT_TZ(checkOut, "+00:00", "+05:30"), "%W %M %e %Y %r") as checkOut_formatted'), 'name', 'phone_no', 'ip_address', 'id', DB::raw('DATE_FORMAT(CONVERT_TZ(created_at, "+00:00", "+05:30"), "%W %M %e %Y %r") as created_at_formatted') ); return DataTables::of($query) ->addIndexColumn() ->make(true); } public function exportCheckInsCSV() { $fileName = 'check_ins_' . date('Y-m-d_H-i-s') . '.csv'; $checkIns = CheckIn::select( 'id', 'checkIn', 'checkOut', 'name', 'phone_no', 'ip_address', 'created_at', 'updated_at' )->orderBy('id', 'DESC')->get(); $headers = [ "Content-type" => "text/csv; charset=UTF-8", "Content-Disposition" => "attachment; filename={$fileName}", "Pragma" => "no-cache", "Cache-Control" => "must-revalidate, post-check=0, pre-check=0", "Expires" => "0" ]; $columns = [ 'ID', 'Check In Date', 'Check Out Date', 'Name', 'Phone Number', 'IP Address', 'Created At', 'Updated At' ]; $callback = function() use ($checkIns, $columns) { $file = fopen('php://output', 'w'); // Add UTF-8 BOM for Excel compatibility fprintf($file, chr(0xEF).chr(0xBB).chr(0xBF)); // Add header row fputcsv($file, $columns); // Add data rows foreach ($checkIns as $row) { fputcsv($file, [ $row->id ?? '', $row->checkIn ?? '', $row->checkOut ?? '', $row->name ?? '', "'" . ($row->phone_no ?? ''), // Force text format for phone $row->ip_address ?? '', $row->created_at ? $row->created_at->format('Y-m-d H:i:s') : '', $row->updated_at ? $row->updated_at->format('Y-m-d H:i:s') : '', ]); } fclose($file); }; return response()->stream($callback, 200, $headers); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings