Giorgiovski
3 months ago
529
6
Laravel

Problem with calling another function from the same controller

Posted 3 months ago by Giorgiovski

I have a page with many forms. I have different routes for the actions. I don't know why when I'm clicking another function actually don't let me submit because it is calling the validate function FROM ANOTHER FUNCTION from the controller.

I receive the message: the session date is required. But the functions are different. Why is called the second function? Thank you.

Form

{!! Form::open(['route' => ['session.updateEverySessionByClick', auth()->user()->id]]) !!}
                                                                        {{Form::text('sessionHourForUpdate', '', ['class' => 'form-control', 'id' => 'sessionHourForUpdate'])}}
                                                                        {{Form::submit('Update session status', ['class' => 'btn btn-sm btn-primary', 'id' => 'submitUpdateStatusOfSession'])}}
                                                                {!!Form::close()!!}

The routes

Route::post('profile/{id}', '[email protected]')->name('session.save');
Route::post('profile/{id}', '[email protected]')->name('session.updateEverySessionByClick');

The controller functions

class SessionController extends Controller
{

    public function updateEverySessionByClick(Request $request, $trainerId){
        $ceva = $request->sessionHourForUpdate;
        return redirect('profile/'.auth()->user()->id)->with('success', $ceva);
    }


    public function saveSession(Request $request, $trainerId){
    
        $this->validate($request,[
            'sessionDate'=>'required',
         ]);

    //rest of the code
    }
}

Please sign in or create an account to participate in this conversation.