-
app/Providers/EventServiceProvider.php
Open in GitHubuse Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Illuminate\Support\Facades\Event; class EventServiceProvider extends ServiceProvider { protected $listen = [ Registered::class => [ SendEmailVerificationNotification::class, ], 'App\Events\Backend\UserCreated' => [ 'App\Listeners\Backend\UserCreated\UserCreatedProfileCreate', 'App\Listeners\Backend\UserCreated\UserCreatedNotifyUser', ], // ]; // }
-
/app/Listeners/Backend/UserCreated/UserCreatedProfileCreate.php
Open in GitHubuse App\Events\Backend\UserCreated; use App\Models\Userprofile; use Illuminate\Contracts\Queue\ShouldQueue; use Log; class UserCreatedProfileCreate implements ShouldQueue { public function handle(UserCreated $event) { $user = $event->user; $userprofile = new Userprofile(); $userprofile->user_id = $user->id; $userprofile->name = $user->name; $userprofile->first_name = $user->first_name; $userprofile->last_name = $user->last_name; $userprofile->username = $user->username; $userprofile->email = $user->email; $userprofile->mobile = $user->mobile; $userprofile->gender = $user->gender; $userprofile->date_of_birth = $user->date_of_birth; $userprofile->avatar = $user->avatar; $userprofile->status = ($user->status > 0) ? $user->status : 0; $userprofile->save(); Log::info('UserCreatedProfileCreate: '.$userprofile->name.'(Id:'.$userprofile->user_id.')'); \Artisan::call('cache:clear'); } }
-
app/Http/Controllers/Backend/UserController.php
Open in GitHubclass UserController extends Controller { // public function store(Request $request) { // $data_array = $request->except('_token', 'roles', 'permissions', 'password_confirmation'); $data_array['name'] = $request->first_name.' '.$request->last_name; $data_array['password'] = Hash::make($request->password); if ($request->confirmed == 1) { $data_array = Arr::add($data_array, 'email_verified_at', Carbon::now()); } else { $data_array = Arr::add($data_array, 'email_verified_at', null); } $$module_name_singular = User::create($data_array); // $id = $$module_name_singular->id; $username = config('app.initial_username') + $id; $$module_name_singular->username = $username; $$module_name_singular->save(); event(new UserCreated($$module_name_singular)); Flash::success("<i class='fas fa-check'></i> New '".Str::singular($module_title)."' Added")->important(); Log::info(label_case($module_title.' '.$module_action)." | '".$$module_name_singular->name.'(ID:'.$$module_name_singular->id.") ' by User:".auth()->user()->name.'(ID:'.auth()->user()->id.')'); return redirect("admin/$module_name"); } // }