117 lines
3.2 KiB
PHP
117 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\ExternalLink;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
|
|
|
|
class ExternalLinkController extends Controller
|
|
{
|
|
function __construct()
|
|
{
|
|
$this->middleware("permission:link.external.list")->only("index");
|
|
$this->middleware("permission:link.external.create")->only(["create", "store"]);
|
|
$this->middleware("permission:link.external.show")->only("show");
|
|
$this->middleware("permission:link.external.edit")->only(["edit", "update"]);
|
|
$this->middleware("permission:link.external.delete")->only("destroy");
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @param Request $request
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
|
|
|
|
return Response::detect("external-links.index", [ "links" => $externalLink ]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function create()
|
|
{
|
|
return Response::detect("external-links.create");
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$requestBody = $request->validate([
|
|
"name" => "required|max:255",
|
|
"link" => "required|max:255"
|
|
]);
|
|
|
|
$externalLink = new ExternalLink($requestBody);
|
|
$externalLink->save();
|
|
|
|
return Response::detect("external-links.store");
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
return Response::detect("external-links.show", [ "link" => $id]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$link = ExternalLink::find($id);
|
|
return Response::detect("external-links.edit", ["link" => $link]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
$data = $request->all();
|
|
|
|
$link = ExternalLink::find($id);
|
|
$link->update($data);
|
|
$link->save();
|
|
|
|
return Response::detect("external-links.update", [ "link" => $link]);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$link = ExternalLink::find($id);
|
|
$link->delete();
|
|
return redirect()->route("external-links.index");
|
|
}
|
|
}
|