0

Given the route:

 Route::get('verify/{id}/{hash}', 'Auth\VerificationController@verify'); 

It uses the Laravel's default verify method from

auth-backend/VerifiesEmails.php 

The default verify method looks like bellow:

public function verify(Request $request) { if (! hash_equals((string) $request->route('id'), (string) $request->user()->getKey())) { throw new AuthorizationException; } if (! hash_equals((string) $request->route('hash'), sha1($request->user()->getEmailForVerification()))) { throw new AuthorizationException; } if ($request->user()->hasVerifiedEmail()) { return $request->wantsJson() ? new Response('', 204) : redirect($this->redirectPath()); } if ($request->user()->markEmailAsVerified()) { event(new Verified($request->user())); } if ($response = $this->verified($request)) { return $response; } return $request->wantsJson() ? new Response('', 204) : redirect($this->redirectPath())->with('verified', true); } 

I would like to change only the last block of the code in the verify method from

 return $request->wantsJson() ? new Response('', 204) : redirect($this->redirectPath())->with('verified', true); 

to

 return $request->wantsJson() ? new Response('', 204) : redirect($this->redirectPath())->with([ 'verified' => true, 'userNotification' => [ 'message' => 'Wellcome to my website', 'title' => 'Hello World', ], ]); 

I know I can override the whole verify method in the VerificationController, which is not ideal to copy and paste the whole block of code for a small change. My question is How can override only the last block of code as mentioned above?

1 Answer 1

2

Right before the final return there is this block:

if ($response = $this->verified($request)) { return $response; 

}

So in your VerificationController you can override just the verified method which is meant for that.

If you look into its source you will see it:

source

So in your local VerificationController add:

protected function verified(Request $request) { return $request->wantsJson() ? new Response('', 204) : redirect($this->redirectPath())->with([ 'verified' => true, 'userNotification' => [ 'message' => 'Wellcome to my website', 'title' => 'Hello World', ], ]); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.