100 lines
1.9 KiB
PHP
100 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\File;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class FileController extends Controller
|
|
{
|
|
/**
|
|
* @param Request $request
|
|
* @return View
|
|
*/
|
|
public function index(Request $request) : view
|
|
{
|
|
$files = File::query()->paginate($request->input("limit", 20));
|
|
return view("files-index", ["files" => $files]);
|
|
}
|
|
|
|
/**
|
|
* @return View
|
|
*/
|
|
public function create() : view
|
|
{
|
|
return view("create-file");
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return RedirectResponse
|
|
*/
|
|
public function store(Request $request) : RedirectResponse
|
|
{
|
|
$rawdata = $request->validate([
|
|
'link' => 'required|string'
|
|
]);
|
|
|
|
$file = new File($rawdata);
|
|
|
|
if($file->save()){
|
|
return redirect()->route("index");
|
|
}
|
|
return redirect()->route("error");
|
|
}
|
|
|
|
/**
|
|
* @param File $file
|
|
* @return View
|
|
*/
|
|
public function show(File $file): View
|
|
{
|
|
return view("show-file",[
|
|
"file" => $file
|
|
]
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @param File $file
|
|
* @return View
|
|
*/
|
|
public function update(Request $request, File $file) : view
|
|
{
|
|
$rawdata = $request->validate([
|
|
'link' => 'required|string'
|
|
]);
|
|
$file->update($rawdata);
|
|
|
|
if(!$file->save()){
|
|
return view("admin.show-file",[
|
|
'file' => $file
|
|
]);
|
|
}
|
|
else{
|
|
return view("admin.show-file",[
|
|
'file' => $file,
|
|
"success" => "Opdaterede file"
|
|
]);
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
* @param File $file
|
|
* @return RedirectResponse
|
|
*/
|
|
public function destroy(File $file): RedirectResponse
|
|
{
|
|
$file->delete();
|
|
return redirect()->route("index");
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|