2020-01-05 23:23:48 +01:00
|
|
|
<?php
|
|
|
|
|
2021-11-07 21:57:22 +01:00
|
|
|
namespace App\Api\v1\Controllers;
|
2020-01-05 23:23:48 +01:00
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
2021-11-07 21:57:22 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
2020-01-05 23:23:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
class IconController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2020-01-08 15:24:34 +01:00
|
|
|
* Handle uploaded icon image
|
2020-01-05 23:23:48 +01:00
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-11-26 11:18:58 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2020-01-05 23:23:48 +01:00
|
|
|
*/
|
|
|
|
public function upload(Request $request)
|
|
|
|
{
|
2020-01-19 23:02:20 +01:00
|
|
|
$this->validate($request, [
|
2020-01-09 16:33:32 +01:00
|
|
|
'icon' => 'required|image',
|
2020-01-12 19:55:17 +01:00
|
|
|
]);
|
|
|
|
|
2020-01-29 22:24:28 +01:00
|
|
|
$path = $request->file('icon')->store('public/icons');
|
2022-07-19 18:27:09 +02:00
|
|
|
$path = $request->file('icon')->store('', 'icons');
|
2021-09-07 23:13:20 +02:00
|
|
|
$response['filename'] = pathinfo($path)['basename'];
|
2020-01-09 16:33:32 +01:00
|
|
|
|
2021-09-07 23:13:20 +02:00
|
|
|
return response()->json($response, 201);
|
2020-01-05 23:23:48 +01:00
|
|
|
}
|
2021-11-26 11:18:58 +01:00
|
|
|
|
2020-01-08 15:24:34 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* delete an icon
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2021-11-26 11:18:58 +01:00
|
|
|
* @return \Illuminate\Http\JsonResponse
|
2020-01-08 15:24:34 +01:00
|
|
|
*/
|
|
|
|
public function delete($icon)
|
|
|
|
{
|
2022-07-19 18:27:09 +02:00
|
|
|
Storage::disk('icons')->delete($icon);
|
2020-01-08 15:24:34 +01:00
|
|
|
|
|
|
|
return response()->json(null, 204);
|
|
|
|
}
|
2020-01-05 23:23:48 +01:00
|
|
|
}
|