Home > Software design >  POST: register return The GET method is not supported for this route. Supported methods: POST in lar
POST: register return The GET method is not supported for this route. Supported methods: POST in lar

Time:02-09

After I deployed my project to server the Route: register start return this:

"message": "The GET method is not supported for this route. Supported methods: POST.",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException",

in localhost, it worked Succesful !!!

My route list is:

| POST| api/register | App\Http\Controllers\Auth\UserAuthController@register

My route in api.php:

Route::post('register', [UserAuthController::class, 'register']);

Controller:

class UserAuthController extends Controller
{
    public function register(Request $request)
    {
        $data = $request->validate([
            'name' => 'required|max:255',
            'email' => 'required|email|unique:users,email',
            'password' => 'required|confirmed',
            'phone_number' => 'required|numeric|unique:users,phone_number',
            'country' => 'required|string',
            'city' => 'required|string',
            'address' => 'string',
            'VIP' => 'boolean'
        ]);

        $data['password'] = bcrypt($request->password);

        $user = User::create($data);

        $token = $user->createToken('API Token')->accessToken;

        return response(['user' => $user, 'token' => $token], 201);
    }

CodePudding user response:

use the commands following

php artisan cache:clear,
php artisan route:cache,
php artisan view:clear,
composer dump-autoload

update:

if it doesn't work check if the url the same {url}/api/register

CodePudding user response:

The problem was from the host not the project, When you face this problem and the project worked in your local host but facing this problem in the server just check if you enable HTTPS protocol in cPanel or in .htacsses in the root path.

After you do this your project should work successfully.

  •  Tags:  
  • Related