IMMREX7
<?php
namespace App\Http\Controllers\School;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use DB;
use Session;
use \App\Http\SendNotificationApi;
class GalleryController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$fy = DB::table('financial_years')->where('idFinancialYear', Session::get('idFinancialYear'))->first();
$folders = \App\GalleryFolder::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->orderBy('created_at','DESC')->whereBetween('created_at', [$fy->startDate . " 00:00:00", $fy->endDate . " 23:59:59"])->paginate();
// $galleries = \App\Gallery::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->get();
return view('schools.gallery.index', compact('folders'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
$fy = DB::table('financial_years')->where('idFinancialYear', Session::get('idFinancialYear'))->first();
$classes = ['' => '--Select--','All'=>'All'] + \App\ClassM::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$folders = ['' => '--Select Folder--'] + \App\GalleryFolder::where('idSchool', '=', Auth::guard('school')->user()->idSchool)->whereBetween('created_at', [$fy->startDate . " 00:00:00", $fy->endDate . " 23:59:59"])
->get()->pluck('folderName', 'idFolder')->toArray();
return view('schools.gallery.gallery_form', compact('folders','classes'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
// dd($request->all());
$rules = [
'idFolder' => 'required',
'imageTitle' => 'required',
// 'image'=>'required|mimes:jpg,jpeg,png|max:100'
];
$this->validate($request, $rules);
$folder = \App\GalleryFolder::where('idFolder', '=', $request->idFolder)->first();
$f_name = $folder->folderName;
if(count($request->file) < 21) {
foreach ($request->file as $key => $value) {
$gallery = new \App\Gallery();
$gallery->fill($request->all());
$gallery->idSchool = Auth::guard('school')->user()->idSchool;
$gallery->idFinancialYear = Session::get('idFinancialYear');
if($request->idClass == 'All'){
$gallery->idClass = null;
}
DB::beginTransaction();
$gallery->save();
$image = 'photo_' . $gallery->idGallery . '.' . $value->getClientOriginalExtension();
$value->storeAs('public/schools/' . Auth::guard('school')->user()->idSchool . '/galleries/' . $f_name . '/', $image);
$gallery->image = $image;
$gallery->update();
DB::commit();
// if($request->idClass == 'All'){
// $reg_ids=DB::table('students')
// ->join('parents', 'students.father_mobile', '=', 'parents.mobile')
// ->select('parents.idFirebase')
// ->where('students.idSchool', Auth::guard('school')->user()->idSchool)
// ->get()->pluck('idFirebase')->toArray();
// SendNotificationApi::sendNotification( $reg_ids,"Gallery : ".$request->imageTitle);
// $reg_ids=DB::table('students')
// ->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
// ->select('parents.idFirebase')
// ->where('students.idSchool', Auth::guard('school')->user()->idSchool)
// ->get()->pluck('idFirebase')->toArray();
// SendNotificationApi::sendNotification( $reg_ids,"Gallery : ".$request->imageTitle);
// }else{
// $reg_ids=DB::table('students')
// ->join('parents', 'students.father_mobile', '=', 'parents.mobile')
// ->select('parents.idFirebase')
// ->where('students.idClass', $request->idClass)
// ->where('students.idSchool', Auth::guard('school')->user()->idSchool)
// ->get()->pluck('idFirebase')->toArray();
// SendNotificationApi::sendNotification( $reg_ids,"Gallery : ".$request->imageTitle);
// $reg_ids=DB::table('students')
// ->join('parents', 'students.mother_mobile', '=', 'parents.mobile')
// ->select('parents.idFirebase')
// ->where('students.idClass', $request->idClass)
// ->where('students.idSchool', Auth::guard('school')->user()->idSchool)
// ->get()->pluck('idFirebase')->toArray();
// SendNotificationApi::sendNotification( $reg_ids,"Gallery : ".$request->imageTitle);
// }
}
return response()->json('success', 200);
}else{
return response()->json('max 20 allowed', 200);
}
// return redirect('school/galleries');
}
/**
* 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) {
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$gallery_img = \App\Gallery::where('idGallery', '=', $id)->first();
$gallery_img->delete();
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
}
Copyright © 2021 -