Home > other >  laravel 8 deployed on heroku error 'Class "App\Classes\Auth\Signup" not found'
laravel 8 deployed on heroku error 'Class "App\Classes\Auth\Signup" not found'

Time:02-10

tried to call a method on Signup class which work fine on localhost but not on production server in throws an error that the class Signup is not found.

Error details

UserController.php:

<?php


namespace App\Http\Controllers;

use App\Classes\Auth\InvalidFieldsException;
use App\Models\User;
use App\Models\Meme;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use App\Classes\Auth\Signup;
use App\Classes\Auth\SignIn;
use App\Mail\SendMail;
use App\Classes\Utils;
use App\Models\Follow;
use App\Models\Upvote;
use Exception;

class UserController extends Controller
{
    /**
     * signUp - handling user's request to sign up to the website. User details are saved in the server's database. The request should have  a user display name, email and password (Validaton requirements in validateSignUp function in SignUp class). After saving user's details a verification message sent to the provided email.
     *
     * @param  Request $request -An object with data of the request, including user details.
     * @return string if succeeded an id of the new user otherwise an error message.
     */
    public function signUp(Request $request)
    {
        try {
            $userData = $request->all();
            if (isset($userData["user"])) {
                $user = $userData["user"];
                Signup::validateSignUp($user);
                $error = "";
                if (User::where('userEmail', '=', $user["userEmail"])->first())
                    $error .= "Email is taken \n";
                if (User::where('displayName', '=', $user["displayName"])->first())
                    $error .= "This display name is taken \n";
                if (!$error) {
                    $password = Utils::hashPassword($user["userPassword"]);
                    $verificationHash = hash('sha256', rand(1, 100000));
                    $userRecord = User::create(['userEmail' => $user["userEmail"], 'displayName' => $user["displayName"], 'userPassword' => $password["userPassword"], 'passwordSalt' =>  $password["passwordSalt"], 'verificationHash' => $verificationHash]);
                    if ($userRecord) {
                        if (SignUp::sendMail($userRecord, $userData["redirect"], $verificationHash))
                            return response()->json($userRecord->id, 200, ["Content-type" => "application/json"]);
                        $error .= "Email could not be sent please use another one ";
                    }
                }

                return response()->json($error, 400, ["Content-type" => "application/json"]);
            }
            return response()->json("User details are missing", 400, ["Content-type" => "application/json"]);
        } catch (InvalidFieldsException $e) {
            return response()->json($e->getMessage(), 400, ["Content-type" => "application/json"]);
        } catch (Exception $e) {
            return response()->json("Error signing up: " . $e->getMessage(), 500, ["Content-type" => "application/json"]);
        }
    }

Signup.php class:

<?php

namespace App\Classes\Auth;

use Illuminate\Support\Facades\Mail;
use App\Mail\SendMail;
use Exception;
use App\Classes\Utils;
use App\Classes\Auth\InvalidFieldsException;

class Signup
{

  /**
   * validateSignUp
   *Make sure all user data is valid setisfies the requirements of the website. if ther's invalid input the script is terminated.
   * @param  array $user - the data that the user enteren in the signup form. 
   */
  public static function validateSignUp(array $user)
  {
    $errorMsg = "";
    if (!isset($user["userEmail"]))
      $errorMsg .= "Email is missing \n";
    else {
      $user["userEmail"] = Utils::testInput($user["userEmail"]);
      if (!filter_var($user["userEmail"], FILTER_VALIDATE_EMAIL)) { //Checking if the email is in correct format.
        $errorMsg .= 'Email is invalid \n';
      }
    }
    if (!isset($user["displayName"]))
      $errorMsg .= "Display is missing \n";
    else {
      $user["displayName"] = Utils::testInput($user["displayName"]);
      if (!preg_match("/^[\w]{2,15}([\s][\w]{1,15})?$/", $user["displayName"])) { // Checking if the display name consists only of letters and numbers, has one or 2 words in length of 2-15 characters for the first and 1-15 for the second.
        $errorMsg .= 'Display name is invalid \n';
      }
    }
    if (!isset($user["userPassword"]))
      $errorMsg .= "Password is missing \n";
    else {
      $user["userPassword"] = Utils::testInput($user["userPassword"]);
      if (!preg_match("/^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[\w!?@#$%^*()<>,;`~]{8,}$/", $user["userPassword"])) { //Checking if the password has at least 8 characters, 1 uppercase leter, 1 lowercase leter and 1 digit.
        $errorMsg .= 'Password is invalid';
      }
    }
    if ($errorMsg)
      throw new InvalidFieldsException($errorMsg);
  }

Tried to use "composer dump-autoload" and clear cache on server, those didn't work. What am I missing here?

CodePudding user response:

May be your class in production was updated or is a symbolic linked and forgotten referenced on the root folder of your server http. On linux look like this:

ln -s to your local folder ...App/Classes/Auth/Signup  /var/www/html/site_folder/...
  •  Tags:  
  • Related