-3

This is my route'

Route::post('/postponse_apps/update_mark',[PostponeApplicationsController::class,'update_mark'])
            ->name('update_mark');
Route::resource('/postponse_apps', PostponeApplicationsController::class);

And this is my function:

    public function update_mark(Request $request, string $id)
    {
        dd($id);
        $app = PostponeApplication::find($id)->update($request->all());
        if($app){
            return redirect()->back();
        }else
            return redirect()->back();
    }

And this is a part of my form:

< form action="{ { route('update_mark', $apply, $apply->id)}}" method="POST" enctype="multipart/form-data">
@csrf
@method('PUT')

when i click the update button, it return this error I have tried to create function in another controller but it not working. I don't know what else should i do to debugg this.

4
  • The update() method mentioned in the error is not about your controller's update() method but the one used in PostponeApplication::find($id)->update(...) - the message telling you that PostponeApplication::find($id) is null
    – brombeer
    Commented Jun 11, 2023 at 8:06
  • Thank you very much sir, although i don't understand why it use the same update function but i can update it now. Commented Jun 11, 2023 at 8:30
  • It doesn't use the same. One is a Controller method update(), the other is a Model method
    – brombeer
    Commented Jun 11, 2023 at 8:31
  • yes sir, but i mean the function apear in the error was public function update and the one i called is public function update_mark. Commented Jun 11, 2023 at 8:49

1 Answer 1

1

Note: In order to improve the code and update existing data, you must use the "PUT" method instead of "POST".

"Indeed, you use put in the form, but you use post in the route"

Regarding your issue, as shown in the attached code, you did not specify any parameters in the route, but you passed a parameter in the form. Additionally, you want to use this parameter in a controller.

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.