Answer the question
In order to leave comments, you need to log in
How to make a browser test for Laravel image upload?
function createPageAutn()
{
$user = User::find(1);
$this->actingAs($user)
->visit('/create')
->see('Add Image')
->attach('image.jpg', __DIR__.'/uploads/image.jpg');
}
Symfony\Component\CssSelector\Exception\SyntaxErrorException:
Expected selector, but <delimiter "/" at 44> found.
$image = $request->file('image');
$description = $request->input('description');
$this->imageClass->add($image, $description);
$this->imageClass->save();
public function add($image, $description)
{
$fileName = $image->store('uploads');
$this->image = $fileName;
$this->description = $description;
$this->id_user = Auth::id();
}
public function updateImage($image, $imgOld)
{
//если пользователь загрузил новую картинку, то заменить её
//если нет, то оставить старую
if($image) {
Storage::delete($imgOld->image);
$fileName = $image->store('uploads');
$this->image = $fileName;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question