<?php
namespace App\Http\Controllers;
use App\Models\Calon;
use App\Models\FileLampiran;
use App\Models\Suara;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
class SuaraController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$q = request()->query('q');
$datas = Suara::with('tps.kelurahan_desa.kecamatan.kabupaten_kota','user');
if(auth()->user()->role == "koordinator-kelurahan-desa"){
$datas = $datas->whereHas('tps',function($w){
$w->where('kelurahan_desa_id',auth()->user()->kelurahan_desa_id);
});
}
if(auth()->user()->role == "koordinator-kecamatan"){
$datas = $datas->whereHas('tps.kelurahan_desa',function($w){
$w->where('kecamatan_id',auth()->user()->kecamatan_id);
});
}
if(auth()->user()->role == "koordinator-kabupaten-kota"){
$datas = $datas->whereHas('tps.kelurahan_desa.kecamatan',function($w){
$w->where('kabupaten_kota_id',auth()->user()->kabupaten_kota_id);
});
}
$datas = $datas->orderBy('created_at','DESC')->simplePaginate(10)->appends(['q'=>$q]);
return view('suara.index',compact('datas','q'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(Suara $suara)
{
$calons = Calon::orderBy('nomor','ASC')->withSum([
'suara_details'=>function($w)use($suara){
$w->where('suara_id',$suara->id);
}
],'jumlah_suara')->get();
return view('suara.show',['suara'=>$suara,'calons'=>$calons]);
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Suara $suara)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Suara $suara)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Suara $suara)
{
//
}
public function status($id , Request $request)
{
$suara = Suara::findOrFail($id);
$suara->update([
'status'=>$request->status
]);
return redirect()->route('suara.index')->with('success','Status berhasil diubah');
}
public function getFileLampiran($id){
$fileLampiran = FileLampiran::findOrFail($id);
$path = $fileLampiran->file;
if(Storage::exists($path)){
//get mimes type
$mimeType = Storage::mimeType($path);
//get file content
$file = Storage::get($path);
//return file
return response($file, 200)->header('Content-Type', $mimeType);
} else {
return abort(404);
}
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]