2020-06-09 07:05:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-06-22 08:08:18 +00:00
|
|
|
use App\ExternalLink;
|
2020-06-09 07:05:07 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-06-24 06:23:15 +00:00
|
|
|
use Illuminate\Http\Response;
|
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
|
|
|
|
class ExternalLinkController extends Controller
|
|
|
|
{
|
2020-06-29 12:28:09 +00:00
|
|
|
function __construct()
|
|
|
|
{
|
2020-07-29 10:30:05 +00:00
|
|
|
$this->middleware([ "auth" ]);
|
|
|
|
|
2020-06-29 12:28:09 +00:00
|
|
|
$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");
|
|
|
|
}
|
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2020-06-22 08:08:18 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
2020-06-22 08:08:18 +00:00
|
|
|
public function index(Request $request)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-06-22 08:08:18 +00:00
|
|
|
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
|
|
|
|
|
2020-06-26 11:56:28 +00:00
|
|
|
return Response::detect("external-links.index", [ "links" => $externalLink ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
2020-06-22 12:53:00 +00:00
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2020-06-23 06:15:44 +00:00
|
|
|
return Response::detect("external-links.create");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2020-06-22 12:53:00 +00:00
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
2020-06-09 07:05:07 +00:00
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-06-22 12:53:00 +00:00
|
|
|
$requestBody = $request->validate([
|
|
|
|
"name" => "required|max:255",
|
|
|
|
"link" => "required|max:255"
|
|
|
|
]);
|
|
|
|
|
|
|
|
$externalLink = new ExternalLink($requestBody);
|
2020-07-01 07:43:11 +00:00
|
|
|
$saved = $externalLink->save();
|
|
|
|
|
|
|
|
if(!$saved){
|
|
|
|
return Response::detect("external-links.store");
|
|
|
|
}else{
|
|
|
|
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
|
|
|
|
return Response::detect("external-links.index", ['links' => $externalLink]);
|
|
|
|
}
|
2020-06-22 12:53:00 +00:00
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
2020-06-26 11:56:28 +00:00
|
|
|
return Response::detect("external-links.show", [ "link" => $id]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2020-06-25 07:15:21 +00:00
|
|
|
$link = ExternalLink::find($id);
|
2020-06-26 11:56:28 +00:00
|
|
|
return Response::detect("external-links.edit", ["link" => $link]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
2020-06-29 07:19:43 +00:00
|
|
|
$data = $request->all();
|
2020-06-25 07:15:21 +00:00
|
|
|
|
2020-06-29 07:19:43 +00:00
|
|
|
$link = ExternalLink::find($id);
|
|
|
|
$link->update($data);
|
2020-07-01 07:43:11 +00:00
|
|
|
$saved = $link->save();
|
|
|
|
|
|
|
|
if(!$saved){
|
|
|
|
return Response::detect("external-links.update", [ "link" => $link]);
|
|
|
|
}else{
|
|
|
|
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
|
|
|
|
return Response::detect("external-links.index", ['links' => $externalLink]);
|
|
|
|
}
|
2020-06-25 07:15:21 +00:00
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2020-06-29 07:19:43 +00:00
|
|
|
$link = ExternalLink::find($id);
|
|
|
|
$link->delete();
|
|
|
|
return redirect()->route("external-links.index");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
}
|