Level 54
You have a typo...
use Symphony\Component\HttpFoundation\File\UploadedFile;
should be
use Symfony\Component\HttpFoundation\File\UploadedFile;
2 likes
Hi
I'm getting the following error.
ErrorException in Photo.php line 69: Argument 1 passed to app\Photo::fromForm() must be an instance of Symphony\Component\HttpFoundation\File\UploadedFile, instance of Symfony\Component\HttpFoundation\File\UploadedFile given
<?php
namespace app;
use Image;
use Illuminate\Database\Eloquent\Model;
use Symphony\Component\HttpFoundation\File\UploadedFile;
//use UploadedFile;
class Photo extends Model
{
protected $table = 'photoshootphotos';
protected $fillable =['path', 'name', 'thumbnail_path'];
protected $baseDir = "photoshoot/photos";
/**
*
* A Photo has one photoshoot
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function photoshoot() {
return $this->belongsTo('seabadger\Photoshoot');
}
public static function named($name)
{
return (new static)->saveAs($name);
}
public function saveAs($name)
{
$this->name = sprintf("%s-%s", time(), $name);
$this->path = sprintf("%s/%s", $this->baseDir, $this->name);
$this->thumbnail_path = sprintf("%s/tn-%s", $this->baseDir, $this->name);
return $this;
}
public function move(UploadedFile $file)
{
$file->move($this->baseDir, $this->name);
$this->makeThumnail();
return $this;
}
protected function makeThumnail()
{
Image::make($this->path)
->fit(200)
->save($this->thumbnail_path);
}
public static function fromForm(UploadedFile $file)
{
$photo = new static;
$name = time() . $file->getClientOriginalName();
$photo->path = $photo->baseDir . '/' . $name;
$file->move($photo->baseDir, $name);
return $photo;
}
}
Any help muchos appreciated
You have a typo...
use Symphony\Component\HttpFoundation\File\UploadedFile;
should be
use Symfony\Component\HttpFoundation\File\UploadedFile;
Please or to participate in this conversation.