File: /var/www/vhost/disk-apps/demo-sigedo.teky.com.co/app/Http/Controllers/CovenantsController.php
<?php
namespace App\Http\Controllers;
use App\Covenant;
use App\Institution;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class CovenantsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
abort_unless(\Gate::allows('covenant_access'), 403);
$covenants = Covenant::with(['institution'])->orderBy('active', 'desc')->orderBy('name', 'asc')->get();
return view('covenants.list', compact('covenants'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
abort_unless(\Gate::allows('covenant_create'), 403);
$institutions = Institution::where('active', true)->orderBy('name', 'asc')->get();
return view('covenants.create', compact('institutions'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
abort_unless(\Gate::allows('covenant_create'), 403);
if ($data = Covenant::create($request->all())) {
$this->registerLogData(json_encode($request->all()), $data->id, 16, 1, Auth::user()->id);
return response(array("status" => true, "type" => "success", "title" => "", "message" => __('created_successfully'), "data" => null));
} else {
return response(array("status" => false, "type" => "error", "title" => "Oops...", "message" => __('error_creating'), "data" => null));
}
}
/**
* Display the specified resource.
*
* @param int $covenant_id
* @return \Illuminate\Http\Response
*/
public function show($covenant_id)
{
abort_unless(\Gate::allows('covenant_show'), 403);
return redirect()->back();
}
/**
* Show the form for editing the specified resource.
*
* @param int $covenant_id
* @return \Illuminate\Http\Response
*/
public function edit($covenant_id)
{
abort_unless(\Gate::allows('covenant_edit'), 403);
$covenant = Covenant::findOrFail($covenant_id);
$institutions = Institution::where('active', true)->orderBy('name', 'asc')->get();
return view('covenants.edit', compact('covenant','institutions'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $covenant_id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $covenant_id)
{
abort_unless(\Gate::allows('covenant_edit'), 403);
if (Covenant::where('id', $covenant_id)->update(array_slice($request->all(), 1))) {
$this->registerLogData(json_encode(array_slice($request->all(), 1)), $covenant_id, 16, 3, Auth::user()->id);
return response(array("status" => true, "type" => "success", "title" => "", "message" => __('updated_successfully'), "data" => null));
} else {
return response(array("status" => false, "type" => "error", "title" => "Oops...", "message" => __('error_updating'), "data" => null));
}
}
/**
* Remove the specified resource from storage.
*
* @param int $covenant_id
* @return \Illuminate\Http\Response
*/
public function destroy($covenant_id)
{
abort_unless(\Gate::allows('covenant_destroy'), 403);
return redirect()->back();
}
}