mozew's avatar
Level 6

array_merge in laravel not working

I want to upload image and after submit a form, I get this error.

The file "C:\xampp\tmp\php1D5F.tmp" does not exist

public function store(ArticleRequest $request)
{
    auth()->loginUsingId(1);
    $imagesUrl = $this->uploadImages($request->file('images'));

    $article = auth()->user()->article()->create(array_merge($request->all(), ['images' => $imagesUrl]));
    $article->categories()->attach(request('category'));


    return redirect(route('articles.index'));
}

I tried Change the code:

    $imagesUrl = $this->uploadImages($request->file('images'));
    return $imagesUrl;

It displaied return $imagesUrl well.

images  
300 "/upload/images/2018/300_tvto.jpg"
600 "/upload/images/2018/600_tvto.jpg"
900 "/upload/images/2018/900_tvto.jpg"
original    "/upload/images/2018/tvto.jpg"
thumb   "/upload/images/2018/300_tvto.jpg"

I think problem from array_merge

0 likes
8 replies
jlrdw's avatar

Do you have

enctype="multipart/form-data"

in your form tag.

mozew's avatar
Level 6

Yes I do it in my form tag.

matt_panton's avatar

Try looking at your phpinfo(). There might be a file size or post size restriction.

Cronix's avatar

You don't show all of your relevant code. What's going on here? Show the uploadImages method.

$imagesUrl = $this->uploadImages($request->file('images'));
Cronix's avatar

And if this is the output for that method

images  
300 "/upload/images/2018/300_tvto.jpg"
600 "/upload/images/2018/600_tvto.jpg"
900 "/upload/images/2018/900_tvto.jpg"
original    "/upload/images/2018/tvto.jpg"
thumb   "/upload/images/2018/300_tvto.jpg"

of course this won't work

$article = auth()->user()->article()->create(array_merge($request->all(), ['images' => $imagesUrl]));

It has nothing to do with array_merge. It has to do with whatever you're doing in this secret method uploadImages($request->file('images')) and what you're trying to save.

jlrdw's avatar

$imagePath = "/upload/images/{$year}/";

Is not a path, it's a url.

You need the path. See helpers in the docs.

Robstar's avatar

Assume you've checked folder permissions, allowed memory amount on the server? Have you tried uploading a very small image first with one thumbnail size.

Please or to participate in this conversation.