Ekapp/skolehjem/app/Http/Controllers/ExternalLinkController.php

108 lines
2.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
2020-06-22 08:08:18 +00:00
use App\ExternalLink;
use Illuminate\Http\Request;
2020-06-24 06:23:15 +00:00
use Illuminate\Http\Response;
class ExternalLinkController extends Controller
{
/**
* 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-22 08:08:18 +00:00
public function index(Request $request)
{
2020-06-22 08:08:18 +00:00
$externalLink = ExternalLink::query()->paginate($request->input("limit", 20));
return Response::detect("external-links.index", [ "links" => $externalLink ]);
}
/**
* 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
*/
public function create()
{
return Response::detect("external-links.create");
}
/**
* 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
*/
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);
$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)
{
2020-06-25 07:15:21 +00:00
$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();
2020-06-25 07:15:21 +00:00
$link = ExternalLink::find($id);
$link->update($data);
$link->save();
2020-06-25 07:15:21 +00:00
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");
}
}