コード例 #1
0
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $user = $this->create($request->all());
     if ($user->role_id == 3) {
         $agent = Agent::with('providers')->get()->sortBy(function ($agent) {
             return $agent->providers()->count();
         })->first();
         $provider = new Provider();
         $provider->agent_id = $agent->id;
         $provider->user_id = $user->id;
         $provider->save();
         Notification::create(['user_id' => $agent->user_id, 'text' => 'Se ha registrado un proveedor', 'url' => route('searchProvider')]);
     } else {
         Mail::send('emails.welcome', ['user' => $user], function ($m) use($user) {
             $m->to($user->email, $user->name)->subject('Bienvenido a Agrosellers!');
         });
     }
     auth()->loginUsingId($user->id);
     return redirect($this->redirectPath());
 }
コード例 #2
0
 function agentsGet()
 {
     return Agent::with(['user' => function ($query) {
         $query->addSelect(['id', 'name'])->get();
     }])->get(['user_id', 'name']);
 }