title: How to fix this error Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined. in laravel 8?
body: <p>i have one controller which contains three functions (register,login,forgotPassword).for login and registration it's working fine but when i try to hit an API in postman i am getting an error,previously i use seperate controller for forgotPassword() function at that time it's working fine ,now i moved that controller into USerController i am getting 500 internal server , please help me to fix this issue..
  <code>UserController.php</code></p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Symfony\Component\HttpFoundation\Response;
  use App\Models\User;
  use Tymon\JWTAuth\Facades\JWTAuth;
  use Tymon\JWTAuth\Exceptions\JWTException;
  use App\Models\PasswordReset;
  use App\Notifications\ResetPasswordNotification;
  
  
  class UserController extends Controller
  {
      public function __construct() {
          $this-&gt;middleware('auth:api', ['except' =&gt; ['login', 'register']]);
      }
      public function register(Request $request)
      {
          $this-&gt;validate($request, [
              'fullName'=&gt;'required|string|between:3,15',
              'email'=&gt;'required|email|unique:users',
              'password'=&gt;'required|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&amp;*-]).{6,}$/',
              'mobile'=&gt;'required|digits:10'
              ]);
          $user = new User([
              'fullName'=&gt; $request-&gt;input('fullName'),
              'email'=&gt; $request-&gt;input('email'),
              'password'=&gt; bcrypt($request-&gt;input('password')),
              'mobile'=&gt;$request-&gt;input('mobile')           
          ]);
          $user-&gt;save();
          // User::create($request-&gt;getAttributes())-&gt;sendEmailVericationNotification();
          return response()-&gt;json(['message'=&gt;'Successfully Created user'],201);
      }
  
      public function login(Request $request)
      {
          $this-&gt;validate($request, [
              'email' =&gt; 'required|email',
              'password' =&gt; 'required'
          ]);
          $credentials = $request-&gt;only('email', 'password');
          try {
              if (!$token = JWTAuth::attempt($credentials)) {
                  return response()-&gt;json(['error' =&gt; 'Invalid Credentials'], 401);
              }
          }catch (JWTException $e) {
              return response()-&gt;json(['error' =&gt; 'Could not create token'],500);
          }
          return response()-&gt;json(['token' =&gt; $token], 200);
      }
  
      public function forgotPassword(Request $request)
      {
          $user = User::where('email', $request-&gt;email)-&gt;first();
          if (!$user) {
              return response()-&gt;json(['error' =&gt; 'Email doesn\'t found on our database'],Response::HTTP_NOT_FOUND);
          }
          $passwordReset = PasswordReset::updateOrCreate(
              ['email' =&gt; $user-&gt;email],
              [
                  'email' =&gt; $user-&gt;email,
                  'token' =&gt; JWTAuth::fromUser($user)
              ]
          );
          if ($user &amp;&amp; $passwordReset) {
              $user-&gt;notify(new ResetPasswordNotification($passwordReset-&gt;token));
          }
          return response()-&gt;json(['data' =&gt; 'Reset link is send successfully, please check your inbox.'], Response::HTTP_OK);
      }
      
  }
  </code></pre>
  <p><code>api.php</code></p>
  <pre><code>&lt;?php
  
  use App\Http\Controllers\UserController;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Route;
  
  
  Route::middleware('auth:api')-&gt;get('/user', function (Request $request) {
      return $request-&gt;user();
  });
  
  
  Route::group([
      'middleware' =&gt; 'api',
      'prefix' =&gt; 'auth'
  ], function ($router) {
      Route::post('/login', [UserController::class, 'login']);
      Route::post('/register', [UserController::class, 'register']);
      Route::post('verifyemail/{token}','VerificationController@verifyEmail');
      Route::post('/sendPasswordResetLink', 'App\Http\Controllers\UserController@forgotPassword');
      Route::post('/resetPassword', 'App\Http\Controllers\ChangePasswordController@resetPassword');
      //Route::get('/email/verify/{id}',[VerificationController::class,'verify']);
  
  });
  </code></pre>
  <p><code>in postman i am getting following error</code></p>
  <pre><code>&lt;!doctype html&gt;&lt;html class=&quot;theme-light&quot;&gt;
  &lt;!--
  Symfony\Component\Routing\Exception\RouteNotFoundException: Route [login] not defined. in file C:\Users\VICKY\Desktop\8\laravel-bookstore\vendor\laravel\framework\src\Illuminate\Routing\UrlGenerator.php on line 427
  
  </code></pre>