2020-01-05 23:23:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-01-09 16:33:32 +01:00
|
|
|
use Validator;
|
2020-01-05 23:23:48 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\File;
|
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function upload(Request $request)
|
|
|
|
{
|
2020-01-09 16:33:32 +01:00
|
|
|
$validator = Validator::make($request->all(), [
|
|
|
|
'icon' => 'required|image',
|
2020-01-12 19:55:17 +01:00
|
|
|
]);
|
2020-01-09 16:33:32 +01:00
|
|
|
|
|
|
|
if ($validator->fails()) {
|
2020-01-14 12:23:31 +01:00
|
|
|
return response()->json(['validation' => $validator->errors()], 400);
|
2020-01-09 16:33:32 +01:00
|
|
|
}
|
2020-01-12 19:55:17 +01:00
|
|
|
|
|
|
|
$path = $request->file('icon')->storePublicly('public/icons');
|
2020-01-09 16:33:32 +01:00
|
|
|
|
2020-01-12 19:55:17 +01:00
|
|
|
return response()->json(pathinfo($path)['basename'], 201);
|
2020-01-05 23:23:48 +01:00
|
|
|
}
|
2020-01-08 15:24:34 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete an icon
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function delete($icon)
|
|
|
|
{
|
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
if( Storage::exists('public/icons/' . $icon) ) {
|
2020-01-08 15:24:34 +01:00
|
|
|
|
2020-01-08 23:22:51 +01:00
|
|
|
Storage::delete('public/icons/' . $icon);
|
2020-01-08 15:24:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json(null, 204);
|
|
|
|
}
|
2020-01-05 23:23:48 +01:00
|
|
|
}
|