/**
  * fonction store pour créer ou éditer
  * @param AdministratorsRequest $request
  * @param $id (facultatif), valeur null par defaut
  *
  */
 public function store(AdministratorsRequest $request, $id = null)
 {
     if (!empty($id)) {
         $administrator = Administrators::find($id);
     } else {
         $administrator = new Administrators();
     }
     $administrator->firstname = $request->firstname;
     $administrator->lastname = $request->lastname;
     $administrator->email = $request->email;
     $administrator->description = $request->description;
     if (!empty($administrator->password)) {
         $administrator->password = bcrypt($request->password);
         //if en mode edit
     }
     $administrator->super_admin = $request->super_admin;
     $administrator->expiration_date = new \DateTime('+1 year');
     $administrator->active = true;
     /**
      * traitement de l'upload de l'image
      */
     $filename = "";
     // si j'ai un fichier image
     if ($request->hasFile('photo')) {
         //recuperation de l'image
         $file = $request->file('photo');
         //recuperation du nom du fichier
         $filename = $file->getClientOriginalName();
         //stockage du chemin vers lequel l'image va etre envoyée
         $destinationPath = public_path() . '/uploads/administrators';
         //deplacement de l'image uploadée
         $file->move($destinationPath, $filename);
         //mise à jour de la propriété de l'objet administrators
         $administrator->photo = asset('/uploads/administrators/' . $filename);
     }
     //sauvegarde de l'objet administrators en base
     $administrator->save();
     //creer un messsage flash de type success
     if (!empty($id)) {
         Session::flash('success', "L'administrateur {$administrator->firstname}  {$administrator->lastname} a bien été modifié.");
     } else {
         Session::flash('success', "L'administrateur {$administrator->firstname}  {$administrator->lastname} a bien été créé.");
     }
     //redirection vers la liste des admins
     return Redirect::route('administrators_index');
 }
 public function edit($id)
 {
     $administrator = Administrators::find($id);
     return view('Administrators/edit', ['administrator' => $administrator]);
 }
 /**
  * Handle the event.
  *
  * @param Events $event
  */
 public function handle(Administrators $user)
 {
     $user->authentificated_at = new \DateTime();
     $user->ip = Request::getClientIp();
     $user->save();
 }
예제 #4
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return Administrators::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
예제 #5
0
 /**
  * Return user if exists; create and return if doesn't.
  *
  * @param $githubUser
  *
  * @return User
  */
 private function findOrCreateUser($githubUser)
 {
     if ($authUser = Administrators::where('github_id', $githubUser->id)->first()) {
         return $authUser;
     }
     return Administrators::create(['name' => $githubUser->name, 'email' => $githubUser->email, 'github_id' => $githubUser->id, 'avatar' => $githubUser->avatar]);
 }