dimanche 17 novembre 2019

error 302 found when post-login in laravel

I create specific gard and register and login when I login to dashboard I need insert program into other table in database after check it not found in table it success login but not inserted to the table I have error 302 found .

route

Route::post('/member/post-login', 'AuthMember\MemberLoginController@postLogin')->name('member.post-login');

controller

public function postLogin(Request $request)
    {
        request()->validate([
        'email' => 'required',
        'password' => 'required',
        ]);

     if (Auth::guard('members')->attempt(['email' => $request->email, 'password' => $request->password,'status'=>'1'], $request->get('remember'))) {
         if((Session::has('ProgramID'))&&(Session::has('CoachID'))){
            $pid=Session::get('ProgramID');
            $cid=Session::get('CoachID');
            $mid= Auth::guard('members')->user()->id;
            $report = member_programs::where('program_id', '=', $pid)
            ->where('member_id', '=', $mid)
            ->where('coache_id', '=', $cid)
            ->first();
            if(!$report){
             $program = new  member_programs();
             $program->program_id =$pid;
             $program->coache_id=$cid;
             $program->member_id =$mid;
             if($program->save()){
                Session::forget('ProgramID');
                Session::forget('CoachID');

        return redirect( route('memberdashboard') )->with([ 'message' => sprintf('Great! You have Successfully loggedin And successfully participated in the program "%s"', $program->program_id),
        'alert-type' => 'success'
        ]);
             }
            }else{
                Session::forget('ProgramID');
                Session::forget('CoachID');
                return redirect( route('memberdashboard') )->with([ 'message' => sprintf('Great! You have Successfully loggedin And Aleardy participated in the program ' ),
                'alert-type' => 'success'
                ]);
            }

            }else{
                return redirect( route('memberdashboard') )->with([ 'message' => sprintf('Great! You have Successfully loggedin'),
               'alert-type' => 'success'
        ]);
            }


    }else{
             return redirect( route('member.login') )->withSuccess('Oppes! You have entered invalid credentials');
    }

}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire