我正在尝试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)
{
//
}
}
素胚勾勒不出你