首页 > 解决方案 > Looking for Laravel php developer to resolve updating function with image uploading its not working

问题描述

It's my update function and it's not showing image when I echo $fileName. It's not working like it was I want to make it with the condition if there is any image then update that image otherwise leave that I tried many times but it's not working.

public function update(Request $request, Header $header)
{

    if($request->hasFile('headerimg')){
        $fileName = $request->file('headerimg')->getClientOriginalName();
        $request->file('headerimg')->move('uploads/header',$fileName);
    }

    $header->title = $request->title;
    $header->discription = $request->discription;
    $header->keywords = $request->keywords;
    $header->headerimg = $fileName;
    $header->h2 = $request->h2;
    $header->breadcumb = $request->breadcumb;
    $header->category = $request->category;
    $header->save();
    return redirect()->route('dashboard.headers.index')->with('success', 'Packages Edited Successfully');
}

标签: phplaravel

解决方案


我想你的问题在你看来。也许您忘记使用enctype="multipart/form-data"或您的输入名称与映射的控制器变量不匹配。

要找到确切的问题,请使用dd($request)dd($request->file('headerimg'))查看您能否获得正确的请求。


推荐阅读