Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

usman9023's avatar

wh failed to load response data : no data found for resource with given identifier

when im trying to dd in my laravel method im getting this :

failed to load response data : no data found for resource with given identifier

here is my method :

 public function register(Request $request)
    {
        dd($request->all());
        // Validate the input data using Laravel's built-in validator
        $validator = Validator::make($request->all(), [
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'role_id' => 'required|exists:roles,id',
        ]);
        // If validation fails, return an error response
        if ($validator->fails()) {
            return response()->json(['error' => $validator->errors()], 422);
        }
        // Find the role based on the given role_id
        $role = Role::find($request->role_id);

        // validate that the role exists
        if (!$role) {
            return response()->json(['error' => 'Invalid role_id'], 422);
        }

        // validate and create new user
        $user = new User([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make($request->password),
        ]);
        // Set the user's role_id and save the user
        $user->role_id = $request->role_id;
        $user->save();

        // Create a token for the user and save it
        $token = $user->createToken('authToken')->accessToken;
        $user->remember_token = $token;
        $user->save();

        // Send an activation email to the user
        // Mail::to($user->email)->send(new UserActivationEmail($token));

        $mail = $user->email;
        $url = env('FRONTEND_URL') . '/activate-account/' . $token;
        Mail::send("Mail.UserActivation", ['token' => $token, 'url' => $url , 'user' => $user->name], function ($message) use ($mail) {
            $message->to($mail);
            $message->from(env('MAIL_FROM_Email'), env('MAIL_FROM_NAME'));
            $message->subject('GrowthTracker Nextbridge User Activation');
        });

        // Return a success response with a message

        return response()->json(['message' => 'Invitation Email has been sent successfully '], 200);
    }

I dont know whats wrong any help would be appreciated

0 likes
3 replies
LaryAI's avatar
Level 58

The issue is not with the code you provided. The error message "failed to load response data : no data found for resource with given identifier" is related to the way Laracasts forum is displaying the response data. It seems like the response data is empty, hence the error message.

To verify that your code is working correctly, you can test it using a tool like Postman or by calling the API endpoint from your frontend application.

If you want to debug the code further, you can try removing the dd($request->all()) line and see if the error message goes away. If it does, then the issue might be related to the way the dd() function is interacting with the Laracasts forum.

Code:

{
    // dd($request->all()); // remove this line
    // Validate the input data using Laravel's built-in validator
    $validator = Validator::make($request->all(), [
        'name' => 'required',
        'email' => 'required|email|unique:users',
        'role_id' => 'required|exists:roles,id',
    ]);
    // If validation fails, return an error response
    if ($validator->fails()) {
        return response()->json(['error' => $validator->errors()], 422);
    }
    // Find the role based on the given role_id
    $role = Role::find($request->role_id);

    // validate that the role exists
    if (!$role) {
        return response()->json(['error' => 'Invalid role_id'], 422);
    }

    // validate and create new user
    $user = new User([
        'name' => $request->name,
        'email' => $request->email,
        'password' => Hash::make($request->password),
    ]);
    // Set the user's role_id and save the user
    $user->role_id = $request->role_id;
    $user->save();

    // Create a token for the user and save it
    $token = $user->createToken('authToken')->accessToken;
    $user->remember_token = $token;
    $user->save();

    // Send an activation email to the user
    // Mail::to($user->email)->send(new UserActivationEmail($token));

    $mail = $user->email;
    $url = env('FRONTEND_URL') . '/activate-account/' . $token;
    Mail::send("Mail.UserActivation", ['token' => $token, 'url' => $url , 'user' => $user->name], function ($message) use ($mail) {
        $message->to($mail);
        $message->from(env('MAIL_FROM_Email'), env('MAIL_FROM_NAME'));
        $message->subject('GrowthTracker Nextbridge User Activation');
    });

    // Return a success response with a message

    return response()->json(['message' => 'Invitation Email has been sent successfully '], 200);
}
tommasovenza's avatar

sorry, I have same problem. I can't make dd( ) of a Javascript or Ajax Request. If I try to access data it returns error 500 and in the network tab there are no information.

How did you solved this problem?

usman9023's avatar

@tommasovenza install this extension "CORS Unblock" , enable it and then try . Hope your issue will be resolved

Please or to participate in this conversation.