DEV Community

Cover image for Laravel: Approve New Registered Users from Administrator

Laravel: Approve New Registered Users from Administrator

Povilas Korop on October 22, 2018

Laravel framework comes with built-in Auth system, which is pretty good. But it doesn't cover all the cases, and the most common one is administrat...
Collapse
 
dm_254 profile image
Douglas Mandela •

Argument 1 passed to App\Notifications\NewUser::__construct() must be an instance of App\Notifications\User, instance of App\User given, called in /var/www/html/adminApprove/app/Http/Controllers/Auth/RegisterController.php on line 76

that error?

Collapse
 
naimroslan profile image
naimroslan •

hi. I am new in Laravel. Have you figured out about this error?

Collapse
 
istavros profile image
Stavros Ioannidis •

People... you just need to add "use App\User;" after the namespace at the top of your file.

Collapse
 
dongosiddik profile image
dongosiddik •

help me
Call to undefined method App\Notifications\NewUser::via()
this is my Controllerregister.php
...
use App\Notifications\NewUser;
...
$user = User::create([
'name' => $data['name'],
'prenom' => $data['prenom'],
'matricule' => $data['matricule'],
'fonction' => $data['fonction'],
'emploi' => $data['emploi'],
// recup id
//'id_role'=> $data['role'],
'id_str'=> $id_str,
'id_direct'=> $id_direct,
'id_ser'=> $id_ser,
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);

$admin = User::where('email', 'dogosidik@gmail.com')->first();
if ($admin) {
$admin->notify(new NewUser($user));
}

return $user;

}

NewUser.php

class NewUser extends Notification
{
use Queueable;

private $new_user;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct(User $new_user)
{
    $this->new_user = $new_user;
}


/**
 * Get the mail representation of the notification.
 *
 * @param  mixed  $notifiable
 * @return \Illuminate\Notifications\Messages\MailMessage
 */
public function toMail($notifiable)
{
    return (new MailMessage)
        ->line('Un nouvel utilisateur a été enregistré par email' .$this->new_user->email)
        ->action('Approve user', route('admin.users', $this->new_user->id));
}

}

Collapse
 
isaacsnipe profile image
isaacsnipe •

ERROR::::

Argument 1 passed to App\Notifications\NewUser::__construct() must be an instance of App\Notifications\User, instance of App\User given, called in C:\xampp\htdocs\staffPortal\app\Http\Controllers\Auth\RegisterController.php on line 75

Help please

Collapse
 
dm_254 profile image
Douglas Mandela •

Hi, help please, am i missing something here ?

Collapse
 
dontito94 profile image
Francis Tito •

may i help you?

Collapse
 
finchy70 profile image
Paul Finch •

I get
Call to undefined method App\Notifications\NewUser::via()
I am using Laravel 5.8

Collapse
 
tanknandita profile image
tankNandita •

Not any error not work this

Collapse
 
tanknandita profile image
tankNandita •

in admin page not showing user that need to approve, and after register notification application not send approval button to admin email. what is missing ?

Collapse
 
andrydupti profile image
lafiolafioli •

in admin page not showing user that need to approve, and after register notification application not send approval button to admin email. what is missing ?