Level 20
You have the wrong import of UploadedFile at the top.
Use UploadedFile;
1 like
So this is my Photo model
<?php
namespace App;
use UploadedFile;
use Illuminate\Database\Eloquent\Model;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class Photo extends Model
{
protected $table = 'flyer_photos';
protected $fillable = ['path'];
protected $baseDir = 'flyers/photos';
public function flyer()
{
return $this->belongsTo('App\Flyer');
}
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;
}
}
And the error I get is
FatalErrorException in Photo.php line 7:
Cannot use Symfony\Component\HttpFoundation\File\UploadedFile as UploadedFile because the name is already in use
But when i write like this
public static function fromForm(Symfony\Component\HttpFoundation\File\UploadedFile\UploadedFile $file)
And try to upload photo then I get a new error
ErrorException in Photo.php line 22:
Argument 1 passed to App\Photo::fromForm() must be an instance of App\Symfony\Component\HttpFoundation\File\UploadedFile\UploadedFile, instance of Symfony\Component\HttpFoundation\File\UploadedFile given, called in C:\xampp\htdocs\project-flyer\app\Http\Controllers\FlyersController.php on line 80 and defined
You have the wrong import of UploadedFile at the top.
Use UploadedFile;
Please or to participate in this conversation.