2020-06-09 07:05:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-06-30 10:22:35 +00:00
|
|
|
use App\Resource;
|
2020-07-27 06:24:16 +00:00
|
|
|
use App\ResourceExtension;
|
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 ResourceController extends Controller
|
|
|
|
{
|
2020-06-30 07:21:21 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware([ "auth" ]);
|
|
|
|
|
|
|
|
$this->middleware([ "check.auth:resource.list" ])->only("index");
|
|
|
|
$this->middleware([ "check.auth:resource.show" ])->only("show");
|
|
|
|
$this->middleware([ "check.auth:resource.create" ])->only("create", "store");
|
|
|
|
$this->middleware([ "check.auth:resource.edit" ])->only("edit", "update");
|
|
|
|
$this->middleware([ "check.auth:resource.delete" ])->only("delete");
|
|
|
|
}
|
|
|
|
|
2020-06-09 07:05:07 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-30 10:22:35 +00:00
|
|
|
public function index(Request $request)
|
2020-06-09 07:05:07 +00:00
|
|
|
{
|
2020-06-30 10:22:35 +00:00
|
|
|
$resources = Resource::query()->paginate($request->input("limit", 20));
|
2020-06-30 08:09:31 +00:00
|
|
|
|
2020-06-30 10:22:35 +00:00
|
|
|
return Response::detect("resources.index", [ "resources" => $resources ]);
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
2020-06-30 10:22:35 +00:00
|
|
|
return Response::detect("resources.create");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-07-27 06:24:16 +00:00
|
|
|
// $data = $request->validate([
|
|
|
|
// "" => ""
|
|
|
|
// ]);
|
2020-06-30 10:22:35 +00:00
|
|
|
|
2020-07-27 06:24:16 +00:00
|
|
|
// $resource = new Resource($data);
|
2020-06-30 10:22:35 +00:00
|
|
|
|
2020-07-27 06:24:16 +00:00
|
|
|
$file = $request->file("resource");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$resourceExtension = ResourceExtension::where("extension", "=", $file->extension())->first();
|
|
|
|
|
|
|
|
if($resourceExtension === null) {
|
|
|
|
//TODO: Create new resourceExtension!
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
$resource = new Resource();
|
|
|
|
|
|
|
|
$resource->resourceExtension()->save($resourceExtension);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$resource->save();
|
|
|
|
}
|
2020-06-30 10:22:35 +00:00
|
|
|
|
|
|
|
return Response::detect("resources.store");
|
2020-06-09 07:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
}
|