我正在尝试resources根据最新的 Laravel 在我的应用程序中每个用户注册后立即保存一些调用到数据库的内容。据我所知,最好的register方法是.../vendor/laravel/framework/src/Illuminate/Foundation/Auth/RegistersUsers.php.所以我在那里添加了 __construct 方法并注入了resourcesService,其中包含createResources将其保存到数据库的方法。不幸的是,该应用程序没有保存任何内容,它甚至没有给我任何错误,所以我不明白出了什么问题。请让我知道你的想法。注册用户.php:namespace Illuminate\Foundation\Auth;use Illuminate\Http\Request;use Illuminate\Support\Facades\Auth;use Illuminate\Auth\Events\Registered;use App\Http\Services\resourcesService;trait RegistersUsers{ public $resourcesService; public function __construct(resourcesService $resourcesService) { $this->resourcesService = $resourcesService; } use RedirectsUsers; /** * Show the application registration form. * * @return \Illuminate\Http\Response */ public function showRegistrationForm() { return view('auth.register'); } /** * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function register(Request $request) { $this->validator($request->all())->validate(); event(new Registered($user = $this->create($request->all()))); $this->guard()->login($user); $this->resourcesService->createResources(); return $this->registered($request, $user) ?: redirect($this->redirectPath()); } /** * Get the guard to be used during registration. * * @return \Illuminate\Contracts\Auth\StatefulGuard */ protected function guard() { return Auth::guard(); } /** * The user has been registered. * * @param \Illuminate\Http\Request $request * @param mixed $user * @return mixed */ protected function registered(Request $request, $user) { // }}
1 回答
素胚勾勒不出你
TA贡献1827条经验 获得超9个赞
在您RegisterController可以覆盖registered在用户成功注册后立即调用的方法:
protected function registered( Request $request, $user )
{
// call your service here.
}
并将其注入控制器的构造函数而不是特征。
同样从您的服务中,我注意到了这一点:
$resources = new $this->resource;
// change it to this:
$resource = new Resource;
并删除依赖注入,因为我认为它没有意义。
- 1 回答
- 0 关注
- 158 浏览
添加回答
举报
0/150
提交
取消