skip to Main Content

I’m currently in the process of developing a Login and Registration system using the Laravel framework. When I run the system, I don’t encounter any errors. However, the problem arises when I attempt to create a new user, as the data doesn’t seem to be getting stored in the database. Here’s the function I’ve implemented for this purpose.

 function loginpost(Request $request)
       {
           $request->validate([
               'email' => 'required|email',
               'password' => 'required'
           ]);
       
           $credentials = $request->only('email', 'password');
           if (Auth::attempt($credentials)) {
               return redirect()->intended(route('home'));
           }
       
           return redirect()->route('login')->with("error", "Email or Password is Invalid");
       }

function regispost(Request $request){
        $request->validate([
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required'
        ]);

        $data['name'] = $request->name;
        $data['email'] = $request->email;
        $data['password'] = Hash::make($request->password);
        $user = User::create($data);
        
       
        if(!$user){
            return redirect(route('regis'))->with("error", "Registration Failed, Try Again");
        }
      

        return redirect(route('login'))->with("success", "Registration Success, Login To Access The Website");


    }

Heres my regis.blade.php

<!DOCTYPE html>
<!-- Coding By CodingNepal - www.codingnepalweb.com -->
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MPorto | Regis</title>
    <link rel="stylesheet" href="{{ asset('assets/css/regis.css') }}">
</head>
<body>
    <nav>
      {{-- Logo --}}
    </nav>
    <div class="form-wrapper">
        <h1>MPORTO</h1>
        <h2>Sign Up</h2>
        <form action="{{ route('regis.post') }}" method="POST">
            @csrf
            <div class="form-control">
                <input type="email" required>
                <label>Email</label>
            </div>
            <div class="form-control">
                <input type="text" required>
                <label>Username</label>
            </div>
            <div class="form-control">
                <input type="password" required>
                <label>Password</label>
            </div>
            <button type="submit">Sign Up</button>
            <div class="form-help"> 
                <div class="remember-me">
                 
                   
                </div>
              
            </div>
        </form>
        <p>Back to Login? <a href="/login">Back</a></p>
       
    </div>
</body>
</html>

2

Answers


  1. As of my last update in September 2021, Laravel 8 was the latest version available. If you’re experiencing issues with user data not getting into the database in Laravel 10 (which might have been released after my last update), the troubleshooting steps would generally be similar to earlier versions of Laravel. Here are some steps you can take to troubleshoot the issue:

    1. Check Database Connection: Ensure that your Laravel application is connected to the correct database. Check your .env file to make sure the database configuration is accurate.

    2. Migrations: If you’re using Laravel’s migration system to create and modify database tables, double-check that the migration files are correct and up-to-date. You might need to run migrations using the php artisan migrate command.

    3. Eloquent Models: If you’re using Eloquent to interact with your database, ensure that your models are properly set up and associated with the correct database tables.

    4. Create Records: If you’re trying to add user data to the database, make sure you’re correctly creating and saving new user records in your code. You can use Eloquent’s create method or instantiate a new model instance and then call save().

    5. Validation: If you’re encountering issues when trying to save user data, check if there are any validation errors preventing the data from being stored. Laravel’s validation system might be blocking the data entry.

    6. Database Logs and Errors: Check your Laravel logs for any error messages related to database interactions. This can give you insights into what might be going wrong.

    7. Testing: If your application includes tests, make sure to run your tests to see if they reveal any issues related to storing user data.

    8. Database Tools: Use database tools (like phpMyAdmin or database CLI tools) to directly inspect the database to verify if data is getting stored.

    9. Debugging: Use Laravel’s built-in debugging tools like dd() or Log::info() to print or log values and see where the data flow might be breaking.

    10. Community Resources: If you’re still facing difficulties, consider seeking help on Laravel forums, GitHub repositories, or other online developer communities. Others might have encountered and resolved similar issues.

    Please keep in mind that my information might not cover any developments related to Laravel 10 that might have occurred after September 2021. Always refer to the latest Laravel documentation and community resources for the most accurate and up-to-date information.

    Login or Signup to reply.
  2. please add names to the input fields

    <input name="name" type="text" required>
    <input name="email" type="email" required>
    <input name="password" type="password" required>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search