Skip to content

Instantly share code, notes, and snippets.

@bayareawebpro
Last active August 19, 2019 03:54
Show Gist options
  • Select an option

  • Save bayareawebpro/fe38a3460fe8425247a866790302156a to your computer and use it in GitHub Desktop.

Select an option

Save bayareawebpro/fe38a3460fe8425247a866790302156a to your computer and use it in GitHub Desktop.
<?php
public function upload()
{
$this->validate($this->request, [
'file' => 'required|image',
]);
$file = $this->request->file('file');
$name = Str::slug(basename($file->getClientOriginalName(), $file->getClientOriginalExtension()));
$name .= ".{$file->getClientOriginalExtension()}";
throw_unless(
!empty($file->storePubliclyAs('public/media', $name)),
new \Exception("File failed to be written.")
);
//Call Image Resize and Save to Same Directory...
$realPath = storage_path("app/public/media/{$name}");
$model->update([
'name' => $name,
'size' => $file->getSize(),
'type' => $file->getMimeType(),
'url' => asset("storage/media/{$name}"),
]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment