IMMREX7
<?php
namespace App\Http\Controllers\School\Library;
use Illuminate\Http\Request;
use App\Http\Controllers\School\SchoolController;
use DB;
use Auth;
class ClassificationController extends SchoolController {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {
$classifications = \App\BookClassification::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClassification', 'desc')->get();
return view('schools.library.classification', compact('classifications'));
}
/**
* 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) {
foreach ($request->classifications as $key => $val) {
$rules['classifications.' . $key . '.classificationName'] = 'unique:book_classifications,classificationName,NULL,idClassification,idSchool,' . Auth::guard('school')->user()->idSchool;
}
$message = [
'classifications.*classificationName.unique' => 'Name Already Exist.',
];
$this->Validate($request, $rules, $message);
foreach ($request->classifications as $var) {
$cf = new \App\BookClassification();
$cf->fill($request->all());
$cf->idSchool = Auth::guard('school')->user()->idSchool;
$cf->classificationName = $var['classificationName'];
$cf->save();
}
flash('Book Classification has been added successfully!!');
if ($request->ajax()) {
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
return redirect('school/classifications');
}
/**
* 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) {
$classifications = \App\BookClassification::where('idSchool', '=', Auth::guard('school')->user()->idSchool)
->orderBy('idClassification', 'desc')->get();
$cf = \App\BookClassification::where('idClassification', '=', $id)->first();
return view('schools.library.classification', compact('classifications', 'cf'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {
$cf = \App\BookClassification::where('idClassification', '=', $id)->first();
$rules = [
'classificationName' => 'required|unique:book_classifications,classificationName,' . $id . ',idClassification,idSchool,' . Auth::guard('school')->user()->idSchool,
];
$this->validate($request, $rules);
$cf->fill($request->all());
$cf->update();
return redirect('school/classifications');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {
$cf = \App\BookClassification::where('idClassification', '=', $id)->first();
$cf->delete();
return response()->json(['success' => "SUCCESS"], 200, ['app-status' => 'success']);
}
}
Copyright © 2021 -