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

osebo-gotokuo's avatar

How To Register or Login Users With Nwidart Laravel-Modules

Hi, i am using the Nwidart Laravel-Modules and so far i have 3 modules, 1)Admin, 2)Core, and 3)Users that handdles user login/registration and so on. The problem is i can's login or register users even though i have the rquirments put inplace. i have my routes like so.

 // join routes
    Route::get('join', 'JoinController@show')->name('join.show');;
    Route::post('join', 'JoinController@join')->name('join.perform');;}

And my joincontroller like so.

 <?php

namespace Modules\Auth\Http\Controllers;

use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Modules\Auth\Entities\User;
use Modules\Auth\Http\Requests\JoinRequest;
use Session;
use Hash;

class JoinController extends Controller
{
    /**
     * Display register page.
     * 
     * @return \Illuminate\Http\Response
     */
    public function show()
    {
        return view('auth::templates/pages.join');
    }

    /**
     * Handle account registration request
     * 
     * @param JoinRequest $request
     * 
     * @return \Illuminate\Http\Response
     */
    public function join(JoinRequest $request) 
    {
        $user = User::create($request->validated());

        auth()->login($user);

        return redirect()->intended('auth::templates.pages.home')->with('success', "Account successfully created.");
    }
}

And my join view like so.

<form method="post" action="{{ route('join.perform') }}">
							    
							   <input type="hidden" name="_token" value="{{ csrf_token() }}" />
							<div class="form-group">	
							  <input type="text" name="username" value="{{ old('username') }}" required="required"/>
							  @if ($errors->has('username'))
                <span class="text-danger text-left">{{ $errors->first('username') }}</span>
            @endif
							  <label class="control-label" for="input">User Name</label><i class="mtrl-select"></i>
							</div>
							<div class="form-group">	
							  <input type="password" name="password" value="{{ old('password') }}" required="required"/>
							  @if ($errors->has('password'))
                <span class="text-danger text-left">{{ $errors->first('password') }}</span>
            @endif
							  <label class="control-label" for="input">Password</label><i class="mtrl-select"></i>
							</div>
							
								<div class="form-group">	
							  <input type="password"  name="password_confirmation" value="{{ old('password_confirmation') }}" required="required"/>
							  @if ($errors->has('password_confirmation'))
                <span class="text-danger text-left">{{ $errors->first('password_confirmation') }}</span>
            @endif
							  <label class="control-label" for="input">Confirm Password</label><i class="mtrl-select"></i>
							</div>
							<div class="form-group">	
							  <input type="email" name="email" value="{{ old('email') }}" required="required"/>
							   @if ($errors->has('email'))
                <span class="text-danger text-left">{{ $errors->first('email') }}</span>
            @endif
							  <label class="control-label" for="input"></label><i class="mtrl-select"></i>
							</div>
							
							<a href="#" title="" class="already-have">Already have an account</a>
							<div class="submit-btns">
								<button class="mtr-btn signin" type="submit"><span>Register</span></button>
							</div>
						</form>

And users model located at Modules/Auth/Entities like so.

<?php

namespace Modules\Auth\Entities;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class User extends Model
{
    use HasFactory;

    protected $fillable = [
        'name',
        'email',
        'username',
        'password',
        ];
    
    protected static function newFactory()
    {
        return \Modules\Auth\Database\factories\UserFactory::new();
    }
    
    /**
 * Always encrypt the password when it is updated.
 *
  * @param $value
 * @return string
 */
public function setPasswordAttribute($value)
{
   $this->attributes['password'] = bcrypt($value);
}
    
}

And Joinrequest like so.

<?php

namespace Modules\Auth\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class JoinRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'email' => 'required|email:rfc,dns|unique:users,email',
            'username' => 'required|unique:users,username',
            'password' => 'required|min:8',
            'password_confirmation' => 'required|same:password'
        ];
    }
}

Now i am lost and confused. Please help. Thanks

0 likes
2 replies
eterlinden's avatar

Hey @osebo-gotokuo

I use Nwidart Laravel-Modules for a lot of projects, so I would like to give you some advice.

Keep all of your User/Roles/Permission related code in the root of your application, since this is considered the 'core' of the framework. Don't try to extract these out into their own modules, it will cause you nothing but problems.

So standard Laravel root app/*

Use the Module/* to extend your core framework functionalities and feature.

I hope this advice finds you well:)

Cheers.

5 likes
osebo-gotokuo's avatar

@eterlinden Thanks a lot, but can you please give a head shoot on how to extend let's say brezz with the module? Please help.

1 like

Please or to participate in this conversation.