D
D
Div-Man2018-12-29 10:23:20
Laravel
Div-Man, 2018-12-29 10:23:20

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');
}

Displays an error
Symfony\Component\CssSelector\Exception\SyntaxErrorException: 
Expected selector, but <delimiter "/" at 44> found.

Here is a regular controller (cropped)
$image = $request->file('image');

 $description = $request->input('description');

 $this->imageClass->add($image, $description);

 $this->imageClass->save();

Here is the model
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 question

Ask a Question

731 491 924 answers to any question