A user can upload an image
and I want to catch the provided $request
image title and convert it to a slug
and save it to the Database
UploadScreenShotController@upload:
public function upload(Request $request)
{
if (!auth()->check()) return $this->with('error', 'Session has ended. Please refresh the page and try again.');
$request->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$image = $request->image;
$filename = $image->getClientOriginalName();
$request->image->move(public_path('images/tcpa/screenshots'), $filename);
return back()
->with('success', 'You have successfully uploaded an image.')
->with('image', $filename);
}
My form:
{!! Form::open(['method' => 'POST', 'files' => 'true', 'route' => ['admin.sms.tcpa-upload-screenshot']])!!}
{!! Form::file('image') !!}
{!! Form::submit('Upload File') !!}
{!! Form::close() !!}
This function
gets the image
name, but it doesn't convert it to a slug
and it doesn't save in the Database
.
How to convert the image
title to a slug
and save it to the Database
?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire