IMMREX7
<?php
namespace App\Http\Controllers\Teacher;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Auth;
use DB;
use Session;
class GalleryController extends TeacherController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
$school = \App\School::where('idSchool','=',$teacher->idSchool)->first();
$galleries = \App\Gallery::where('idSchool', '=', $teacher->idSchool)->paginate(25);
return view('teachers.gallery.index', compact('galleries','classes','school'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {
$teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
$school = \App\School::where('idSchool','=',$teacher->idSchool)->first();
$classes = ['' => '--Select--','All'=>'All'] + \App\ClassM::where('idSchool', '=', $teacher->idSchool)
->orderBy('idClass')->get()->pluck('className', 'idClass')->toArray();
$folders = ['' => '--Select Folder--'] + \App\GalleryFolder::where('idSchool', '=', $teacher->idSchool)
->get()->pluck('folderName', 'idFolder')->toArray();
return view('teachers.gallery.gallery_form', compact('folders','classes','school'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request) {
// dd($request->all());
$teacher = \App\Teacher::where('idEmployee', '=', Auth::guard('teacher')->user()->idEmployee)->first();
$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;
foreach ($request->file as $key => $value) {
$gallery = new \App\Gallery();
$gallery->fill($request->all());
$gallery->idSchool = $teacher->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/' . $teacher->idSchool . '/galleries/' . $f_name . '/', $image);
$gallery->image = $image;
$gallery->update();
DB::commit();
}
return response()->json('success', 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 -