lundi 7 mai 2018

BadMethodCallException in Macroable.php line 74: Method update does not exist

I want to update a document using the source code below

public function update(Request $request, $id)
{
    $this->validate($request, [
       'name' => 'required',
    ]);

    $document = Document::find($id);
    $data = $request->all();

    if ($request->hasFile('document')) {
        $exist = Storage::disk('document')->exists($document->document);
        if (isset($document->document) && $exist) {
            $delete = Storage::disk('document')->delete($document->document);
        }

        $document = $request->file('document');
        $ext = $document->getClientOriginalExtension();

        if ($request->file('document')->isValid()) {
            $documentName = date('YmdHis') . ".$ext";
            $path = 'docs';
            $request->file('document')->move($path, $documentName);
            $data['document'] = $documentName;
        }
    }

    $document->update($data);

    Session::flash('flash_notification', 'Success updated.');
    return redirect('documents');
}

but when I click the update button, the source code is error with BadMethodCallException in Macroable.php line 74: Method update does not exist. Why did it happen? what is wrong in writing my code? thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire