<img src="https://pp.userapi.com/c636721/v636721443/5ab91/mKddcLFmkqs.jpg"/>
class Image
{
/**
* @var UploadedFile
*/
public $file;
/**
* Image constructor.
* @param UploadedFile $file
*/
public function __construct(UploadedFile $file)
{
$this->file = $file;
}
/**
* @return string
*/
public function hash() {
return $this->file->hashName();
}
/**
* @return null|string
*/
public function saveFile() {
$name = $this->hash();
if($this->file->move(public_path() . '/imgs', $name)) {
return $name;
}
return null;
}
}
/**
* @param JournalStoreRequest $request
*/
public function store(JournalStoreRequest $request) {
// надеюсь что в валидации стоит поле image как обязательный и проверка на файл идет
$image = new Image($request->file($this->getImageParamName()));
$journal = new Journal(
array_merge(
$request->only([ '', '' ]),
[ 'image' => $image->saveFile(), ]
)
);
$journal->save() ? redirect()->route($this->redirectRoute()) : abort(505);
}
/**
* @return string
*/
protected function redirectRoute() {
return 'journals.index';
}
/**
* @return string
*/
protected function getImageParamName() {
return 'image';
}
canvas.translate(d3.event.translate[0], d3.event.translate[1]);
canvas.scale(d3.event.scale, d3.event.scale);