2FAuth/app/Http/Controllers/IconController.php

42 lines
908 B
PHP
Raw Normal View History

2020-01-05 23:23:48 +01:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
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)
{
$this->validate($request, [
'icon' => 'required|image',
]);
$path = $request->file('icon')->store('public/icons');
2021-09-07 23:13:20 +02:00
$response['filename'] = pathinfo($path)['basename'];
2021-09-07 23:13:20 +02:00
return response()->json($response, 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-27 13:35:47 +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
}