Php 如何更新Laravel上的现有列

Php 如何更新Laravel上的现有列,php,mysql,laravel,eloquent,summernote,Php,Mysql,Laravel,Eloquent,Summernote,我有一个页面,我可以使用summernote添加内容。但当我更新内容时,没有任何更改 这是我的店主。 public function store(Request $request) { $detail=$request->content; $dom = new DOMDocument(); $dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); $images = $

我有一个页面,我可以使用summernote添加内容。但当我更新内容时,没有任何更改

这是我的店主。

public function store(Request $request)
{
    $detail=$request->content;
    $dom = new DOMDocument();
    $dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
    $images = $dom->getelementsbytagname('img');
    foreach($images as $k => $img){
        $data = $img->getattribute('src');
        list($type, $data) = explode(';', $data);
        list(, $data)      = explode(',', $data);
        $data = base64_decode($data);
        $image_name= time().$k.'.png';
        $path = public_path('uploads') .'/'. $image_name;

        file_put_contents($path, $data);

        $img->removeattribute('src');
        $img->setattribute('src', 'uploads'.'/'.$image_name);
    }

    $detail = $dom->savehtml();
    $abouts = new about;
    $abouts->content = $detail;
    $abouts->save();
    return view('admin.about',compact('abouts'));
}
这是我的UpdateControl

    public function update(Request $request)
    {
        if($request->isMethod('POST')){

            //in this section all code are same as like as my store controller
            
            $abouts->update();
            return view('admin.about',compact('abouts'));
        }

    }

关于如何解决这个问题有什么想法吗?

如果您正在请求中获取数据,或者没有使用
dd()
方法,那么最好的解决方案是首先测试它。或

您可以尝试以下方法:

public function update(Request $request)
{
    if($request->isMethod('PUT')){

        //in this section all code are same as like as my store controller
        
        $abouts->update();
        return view('admin.about',compact('abouts'));
    }

}
或者,您可以删除该条件,然后重试

public function update(Request $request)
{
    

        //in this section all code are same as like as my store controller
        
        $abouts->update();
        return view('admin.about',compact('abouts'));
    

}

在存储功能中,您使用了以下
$abouts=newabout
在更新函数中是否也执行相同的操作?然后它将是一个新实例

添加验证可能会帮助您了解未更新的原因

\Log::debug('message')也很有用

public function update($id, Request $request)
{
    //you can pass $id of the record which you want to update or even pass it along with the other request parameters.
    $task = Task::findOrFail($id);

    //validate the request( would suggest to do the same in your store function too. )
    $this->validate($request, [
        'title' => 'required',
        'description' => 'required'
    ]);

    $input = $request->all();

    $task->fill($input)->save();

    Session::flash('flash_message', 'Task successfully added!');

    return redirect()->back();
}

您正在创建Abouti的新实例如果在controller的更新方法中创建新实例是正确的,那么您应该检查about模型并确保它具有可用的$fillable数组。是的,它已保护$fillable=['content'];当您执行dd($detail)时,是否有任何数据?请执行dd()并检查在您尝试存储数据时发生的情况,您将确切地知道我也尝试使用此方法@Naveed Ali