You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.2 KiB
126 lines
3.2 KiB
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use fullMstr;
|
|
use Illuminate\Http\Request;
|
|
|
|
class MastersController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the singleMstr.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$editableMaster = null;
|
|
$mstrCollections = Master::where(function ($query) {
|
|
$query->where('name', 'like', '%'.request('q').'%');
|
|
})->paginate(25);
|
|
|
|
if (in_array(request('action'), ['edit', 'delete']) && request('id') != null) {
|
|
$editableMaster = Master::find(request('id'));
|
|
}
|
|
|
|
return view('masters.index', compact('mstrCollections', 'editableMaster'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new singleMstr.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$this->authorize('create', new Master);
|
|
|
|
return view('masters.create');
|
|
}
|
|
|
|
/**
|
|
* Store a newly created singleMstr in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$this->authorize('create', new Master);
|
|
|
|
$this->validate($request, [
|
|
'name' => 'required|max:60',
|
|
'description' => 'nullable|max:255',
|
|
]);
|
|
|
|
$singleMstr = Master::create($request->only('name', 'description'));
|
|
|
|
return redirect()->route('masters.show', $singleMstr);
|
|
}
|
|
|
|
/**
|
|
* Display the specified singleMstr.
|
|
*
|
|
* @param \App\Master $singleMstr
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Master $singleMstr)
|
|
{
|
|
return view('masters.show', compact('singleMstr'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified singleMstr.
|
|
*
|
|
* @param \App\Master $singleMstr
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit(Master $singleMstr)
|
|
{
|
|
return view('masters.edit', compact('singleMstr'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified singleMstr in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param \fullMstr $singleMstr
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, Master $singleMstr)
|
|
{
|
|
$this->authorize('update', $singleMstr);
|
|
|
|
$this->validate($request, [
|
|
'name' => 'required|max:60',
|
|
'description' => 'nullable|max:255',
|
|
]);
|
|
|
|
$singleMstr = $singleMstr->update($request->only('name', 'description'));
|
|
|
|
return redirect()->route('masters.show', $singleMstr);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified singleMstr from storage.
|
|
*
|
|
* @param \fullMstr $singleMstr
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Master $singleMstr)
|
|
{
|
|
$this->authorize('delete', $singleMstr);
|
|
|
|
$this->validate(request(), [
|
|
'master_id' => 'required',
|
|
]);
|
|
|
|
$routeParam = request()->only('page', 'q');
|
|
|
|
if (request('master_id') == $singleMstr->id && $singleMstr->delete()) {
|
|
return redirect()->route('masters.index', $routeParam);
|
|
}
|
|
|
|
return back();
|
|
}
|
|
}
|