54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Image;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Str;
|
|
|
|
class ImageController extends Controller
|
|
{
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
return view("uploadImage");
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validatedData = $request->validate([
|
|
// The server should make sure to serve SVG files with the correct CSP to prevent XSS
|
|
'image' => 'required|image|mimes:jpg,png,jpeg,gif,svg,webp|max:5000',
|
|
]);
|
|
/*
|
|
Once the image is validated , create the name on the image
|
|
*/
|
|
$image = new Image();
|
|
|
|
$image->uuid = Str::uuid();
|
|
$image->path = $request->file('image')->store("uploads");
|
|
|
|
$image->save();
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param \App\Models\Image $image
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy(Image $image)
|
|
{
|
|
$image->delete();
|
|
}
|
|
}
|