Overview

Namespaces

  • App
    • Http
      • Controllers
        • Auth
      • Middleware
  • PHP

Classes

  • App\Ad
  • App\AdClick
  • App\AdLocation
  • App\Comment
  • App\Driver
  • App\Emergency
  • App\Http\Controllers\AdController
  • App\Http\Controllers\ApiController
  • App\Http\Controllers\Auth\AuthController
  • App\Http\Controllers\Auth\PasswordController
  • App\Http\Controllers\CommentController
  • App\Http\Controllers\Controller
  • App\Http\Controllers\EmergencyController
  • App\Http\Controllers\NewspaperController
  • App\Http\Controllers\RouteController
  • App\Http\Controllers\TaxiController
  • App\Http\Controllers\UserController
  • App\Http\Kernel
  • App\Http\Middleware\AddHeaders
  • App\Http\Middleware\AdminMiddleware
  • App\Newspaper
  • App\Route
  • App\Tablet
  • App\Taxi
  • App\Taxibase
  • App\User
  • Closure
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace App\Http\Controllers;
  4: 
  5: use App\Driver;
  6: use App\Newspaper;
  7: use App\Taxibase;
  8: use App\User;
  9: use Illuminate\Http\Request;
 10: use App\Http\Requests;
 11: use App\Http\Controllers\Controller;
 12: use Illuminate\Support\Facades\Auth;
 13: use Route, View;
 14: use Illuminate\Support\Facades\Validator;
 15: use App\Taxi;
 16: use App\Comment;
 17: use App\Tablet;
 18: use Illuminate\Support\Facades\Hash as Hash;
 19: use Image;
 20: use File;
 21: use App\Http\Controllers\Storage;
 22: 
 23: class UserController extends Controller
 24: {
 25:     /**
 26:      * @author Stefano Groenland
 27:      * @return mixed
 28:      *
 29:      * Makes the index view.
 30:      */
 31:     public function showIndex(){
 32:         $cars = Taxi::with('emergency','driver')->where('in_shift',1)->where('last_latitude','!=','')->where('last_longtitude','!=','')->get();
 33:         $bases = Taxibase::all();
 34:         $today = date('Y-m-d');
 35:         $routeCount = 0;
 36:         $countCars = count(Taxi::where('in_shift',1)->get());
 37:         $countRoutes = \App\Route::where('processed',1)->get();
 38: 
 39:         foreach($countRoutes as $route){
 40:             if(date('Y-m-d',strtotime($route->pickup_time)) == $today){
 41:                 if(Auth::user()->user_rank != 'admin'){
 42:                     if($route->taxi && $route->taxi->driver){
 43:                         if($route->taxi->driver->user_id == Auth::user()->id){
 44:                             $routeCount++;
 45:                         }
 46:                     }
 47:                 }else{
 48:                     $routeCount++;
 49:                 }
 50:             }
 51:         }
 52:         $countOpenRoutes = count(\App\Route::where('processed',0)->get());
 53:         $driver = Driver::with('user')->where('user_id',Auth::user()->id)->first();
 54:         if(Auth::user()->user_rank != 'admin'){
 55:             $countComments = count(Comment::where('approved',1)->where('seen',0)->where('driver_id',$driver->id)->get());
 56:         }else{
 57:             $countComments = count(Comment::where('approved',0)->get());
 58:         }
 59: 
 60:         return View::make('/index',compact('bases','today','routeCount','countCars','countOpenRoutes','countComments','cars'));
 61:     }
 62: 
 63:     /**
 64:      * @author Stefano Groenland
 65:      * @return mixed
 66:      *
 67:      * Makes the profile view and passes a variable of comments with it.
 68:      */
 69:     public function showProfile(){
 70:         $driver = Driver::with('user')->where('user_id',Auth::user()->id)->first();
 71:         $comments = Comment::with('driver')->where('approved','=','1')->get();
 72: 
 73:         foreach($comments as $comment){
 74:             if($driver){
 75:                 $comment->where('driver_id',$driver->id)->update(['seen' => 1]);
 76:             }
 77:         }
 78:         if(Auth::user()->user_rank == 'admin'){
 79:             return $this->showProfileEdit();
 80:         }else{
 81:             return View::make('/profiel', compact('comments'));
 82:         }
 83:     }
 84: 
 85:     /**
 86:      * @author Richard Perdaan
 87:      * @return mixed
 88:      *
 89:      *  Grabs the ID of the current user, looks for a user with that ID, and returns the id and making the View.
 90:      */
 91:     public function showProfileEdit(){
 92:         $id = Auth::user()->id;
 93:         return View::make('/profielwijzigen', compact('id'));
 94:     }
 95: 
 96:     /**
 97:      * @author Stefano Groenland
 98:      * @return mixed
 99:      *
100:      * Makes the drivers overview view and passes a series of variables with it.
101:      */
102:     public function showDrivers(){
103:         $drivers = Driver::with('user','taxi','comment')->get();
104:         return View::make('/chauffeurs', compact('drivers','taxis','comment'));
105:     }
106: 
107:     /**
108:      * @author Richard Perdaan
109:      * @return mixed
110:      *
111:      * Gets the id of the corresponding driver to define which driver will be shown in the view,
112:      * and defines a series of 2 other variables to show the car count available and all cars.
113:      */
114:     public function showDriversEdit(){
115:         $id         = Route::current()->getParameter('id');
116:         $driver     = Driver::with('user')->where('user_id','=',$id)->first();
117:         $cars       = Taxi::where('driver_id','=','0')->orWhere('driver_id',$driver->id)->get();
118:         $carCount   = count($cars);
119:         return View::make('/chauffeurwijzigen', compact('id','driver','cars','carCount'));  
120:     }
121: 
122:     /**
123:      * @author Richard Perdaan
124:      * @return mixed
125:      *
126:      * Gets all cars and passes them along with the view so a new driver can be assigned to a available car.
127:      */
128:     public function showDriversAdd(){
129:         $cars       = Taxi::where('driver_id','=','0')->get();
130:         $carCount   = count($cars);
131:         return View::make('/chauffeurtoevoegen', compact('cars','carCount'));
132:     }
133: 
134:     /**
135:      * @author Stefano Groenland
136:      * @return mixed
137:      *
138:      * Gets all the tablets which are linked to a taxi and passes them along when making the view.
139:      */
140:     public function showTablet(){
141:         $tablets = Tablet::with('taxi','user')->get();
142:         return View::make('/tablets', compact('tablets'));
143:     }
144: 
145:     /**
146:      * @author Stefano Groenland
147:      * @return mixed
148:      *
149:      *  TODO : fill in func description
150:      */
151:     public function showTabletAdd(){
152:         $cars   = Taxi::all();
153:         return View::make('/tablettoevoegen', compact('cars'));
154:     }
155: 
156:     /**
157:      * @author Stefano Groenland
158:      * @return mixed
159:      *
160:      *  TODO : fill in func description
161:      */
162:     public function showTabletEdit(){
163:         $id     = Route::current()->getParameter('id');
164:         $tablet = Tablet::where('id',$id)->first();
165:         $user   = User::where('id',$tablet->user_id)->first();
166:         $cars   = Taxi::all();
167:         return View::make('/tabletwijzigen',compact('id','tablet','user','cars'));
168:     }
169: 
170:     /**
171:      * @author Stefano Groenland
172:      * @return mixed
173:      *
174:      * Grabs all users with the user rank 'admin' out the database and passes them when making the view.
175:      */
176:     public function showAdmin(){
177:         $admins = User::where('user_rank','=','admin')->get();
178:         return View::make('/medewerkers',compact('admins'));
179:     }
180: 
181:     /**
182:      * @author Stefano Groenland
183:      * @return mixed
184:      *
185:      *  Grabs the ID of the current route, looks for a user with that ID, and returns both the id and the User found along while making the View.
186:      */
187:     public function showAdminEdit(){
188:         $id = Route::current()->getParameter('id');
189:         $admin = User::where('id',$id)->first();
190: 
191:         return View::make('/medewerkerwijzigen',compact('admin','id'));
192:     }
193: 
194:     /**
195:      * @author Stefano Groenland
196:      * @return mixed
197:      *
198:      * Uses the route parameter to define which user has to be edited,
199:      * Gets all inputs filled in and checks them for validation. If all passed correctly the User gets updated.
200:      */
201:     public function editAdmin(Request $request){
202:         $id = Route::current()->getParameter('id');
203:         $user = User::where('id','=',$id)->first();
204: 
205:         $userData = array(
206:             'email'                 => $request['email'],
207:             'phone_number'          => $request['phonenumber'],
208:             'firstname'             => $request['firstname'],
209:             'lastname'              => $request['lastname'],
210:             'password'              => $request['password'],
211:             'password_confirmation' => $request['password_confirmation'],
212:             'sex'                   => $request['sex'],
213:         );
214:         $userRules = array(
215:             'email'                 => 'required|email',
216:             'phone_number'          => 'required|numeric|digits:10',
217:             'firstname'             => 'required',
218:             'lastname'              => 'required',
219:             'password'              => 'min:4',
220:             'password_confirmation' => 'min:4',
221:             'sex'                   => 'required|in:man,vrouw'
222:         );
223:         $validator = Validator::make($userData, $userRules);
224:         if ($validator->fails()){
225:             return redirect('medewerkerwijzigen/'.$id)->withErrors($validator)->withInput($userData);
226:         }
227: 
228:         if (empty($userData['password']) || empty($userData['password_confirmation'])) {
229:             array_forget($userData, 'password');
230:             array_forget($userData, 'password_confirmation');
231:         }
232: 
233:         if (array_key_exists('password', $userData)) {
234:             $userData['password'] = Hash::make($userData['password']);
235:             array_forget($userData, 'password_confirmation');
236:         } else {
237:             User::where('id', '=', $id)->update($userData);
238:             $this->upload($request, $id);
239:             $request->session()->flash('alert-success', 'Medewerker account is gewijziged, er zijn geen wijzigingen aan het wachtwoord doorgevoerd.');
240:             return redirect('/medewerkers');
241:         }
242: 
243:         $user->update($userData);
244:         $request->session()->flash('alert-success', 'Het account met e-mail '. $user->email .' is gewijziged.');
245:         $this->upload($request, $id, 1);
246:         return redirect('/medewerkers');
247: 
248:     }
249: 
250:     /**
251:      * @author Stefano Groenland
252:      * @return \Illuminate\Http\RedirectResponse
253:      *
254:      * Uses the route parameter to define which corresponding user is selected,
255:      * then deletes the user from the database. It even deletes their profile picture from the server!
256:      */
257:     public function deleteAdmin(){
258:         $id  = Route::current()->getParameter('id');
259:         $find = User::find($id);
260: 
261:         User::where('id','=',$id)->delete();
262:         if(!$find->profile_photo == ""){
263:             unlink($find->profile_photo);
264:         }
265:         session()->flash('alert-success', 'Medewerker '. $find->firstname.' verwijderd.');
266:         return redirect()->route('medewerkers');
267:     }
268: 
269:     /**
270:      * @author Stefano Groenland
271:      * @return mixed
272:      *
273:      * Makes the view for showing the form for adding a new admin user.
274:      */
275:     public function showAdminAdd(){
276:         return View::make('/medewerkertoevoegen');
277:     }
278: 
279:     /**
280:      * @author Stefano Groenland
281:      * @param Request $request
282:      * @return \Illuminate\Http\RedirectResponse
283:      *
284:      * Uses the request parameter to define all inputs ,
285:      * checks all inputs passed if they are filled in correctly and then makes the User.
286:      *
287:      */
288:     public function addAdmin(Request $request){
289:         $userData = array(
290:             'email'                 => $request['email'],
291:             'phone_number'          => $request['phonenumber'],
292:             'firstname'             => $request['firstname'],
293:             'lastname'              => $request['lastname'],
294:             'password'              => $request['password'],
295:             'password_confirmation' => $request['password_confirmation'],
296:             'sex'                   => $request['sex'],
297:             'user_rank' => 'admin'
298:         );
299: 
300:         $userRules = array(
301:             'email'                 => 'required|email|unique:user',
302:             'phone_number'          => 'required|numeric|digits:10',
303:             'firstname'             => 'required',
304:             'lastname'              => 'required',
305:             'password'              => 'required|min:4|confirmed',
306:             'password_confirmation' => 'required|min:4',
307:             'sex'                   => 'required|in:man,vrouw'
308:         );
309:         $validator = Validator::make($userData, $userRules);
310:         if ($validator->fails()){
311:             return redirect('medewerkertoevoegen')->withErrors($validator)->withInput($userData);
312:         }
313:         array_forget($userData, 'password_confirmation');
314:         $userData['password'] = Hash::make($request['password']);
315:         $user = User::create($userData);
316: 
317:         $this->upload($request,$user->id,1);
318: 
319:         $request->session()->flash('alert-success', 'De medewerker is toegevoegd.');
320:         return redirect()->route('medewerkers');
321:     }
322: 
323:     /**
324:      * @author Richard Perdaan
325:      * @param Request $request
326:      * @return \Illuminate\Http\RedirectResponse
327:      *
328:      * Uses the request parameter to define all inputs ,
329:      * checks all inputs passed if they are filled in correctly and then makes the Driver with linked user details.
330:      *
331:      */
332:     public function addDriver(Request $request){
333:         $userData = array(
334:             'email'                 => $request['email'],
335:             'phone_number'          => $request['phonenumber'],
336:             'firstname'             => $request['firstname'],
337:             'lastname'              => $request['lastname'],
338:             'password'              => $request['password'],
339:             'password_confirmation' => $request['password_confirmation'],
340:             'sex'                   => $request['sex'],
341:             'drivers_exp'           => $request['driver_exp'],
342:             'global_information'    => $request['global_information'],
343:             'user_rank'             => 'driver'
344:         );
345: 
346:         $userRules = array(
347:             'email'                 =>'required|email|unique:user',
348:             'phone_number'          =>'required|numeric|digits:10',
349:             'firstname'             =>'required',
350:             'lastname'              =>'required',
351:             'password'              => 'required|min:4|confirmed',
352:             'password_confirmation' => 'required|min:4',
353:             'drivers_exp'           => 'numeric',
354:             'sex'                   => 'required|in:man,vrouw'
355:         );
356: 
357:         $validator = Validator::make($userData, $userRules);
358:         if ($validator->fails()){
359:             return redirect('chauffeurtoevoegen')->withErrors($validator)->withInput($userData);
360:         }
361:         array_forget($userData, 'password_confirmation');
362:         $userData['password'] = Hash::make($request['password']);
363:         $user = User::create($userData);
364: 
365:         $this->upload($request,$user->id);
366: 
367:         $driverData = array(
368:             'user_id'               => $user->id,
369:             'drivers_exp'           => $request['driver_exp'],
370:             'global_information'    => $request['global_information']
371:         );
372: 
373:         $driver = Driver::create($driverData);
374:         $taxiData = array(
375:             'driver_id' => $driver->id
376:         );
377: 
378:         Taxi::where('id','=', $request['car'])->update($taxiData);
379:         $request->session()->flash('alert-success', 'De chauffeur is toegevoegd.');
380:         return redirect()->route('chauffeurs');
381:     }
382: 
383:     /**
384:      * @author Richard Perdaan
385:      * @return \Illuminate\Http\RedirectResponse
386:      *
387:      * Uses the route parameter to define which corresponding driver is selected,
388:      * then deletes the driver and linked user account from the database.
389:      */
390:     public function deleteDriver(){
391:         $id  = Route::current()->getParameter('id');
392:         $find = User::find($id);
393:         $driver = Driver::where('user_id','=',$find->id)->first();
394:         Taxi::where('driver_id','=',$driver->id)->update(array('driver_id' => 0));
395:         $find->delete();
396:         $driver->delete();
397:         if(!$find->profile_photo == ""){
398:             unlink($find->profile_photo);
399:         }
400:         session()->flash('alert-success', 'chauffeur '. $find->firstname.' verwijderd.');
401:         return redirect()->route('chauffeurs');
402:     }
403: 
404:     /**
405:      * @author Richard Perdaan
406:      * @param Request $request
407:      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
408:      *
409:      * Uses the route parameter to define which driver has to be edited,
410:      * Gets all inputs filled in and checks them for validation. If all passed correctly the Driver gets updated.
411:      */
412:     public function editDriver(Request $request){
413:        
414:         $id = Route::current()->getParameter('id');
415:         $driver = Driver::where('user_id','=',$id)->first();
416: 
417:         $userData = array(
418:             'email'                 => $request['email'],
419:             'phone_number'          => $request['phonenumber'],
420:             'firstname'             => $request['firstname'],
421:             'lastname'              => $request['lastname'],
422:             'password'              => $request['password'],
423:             'password_confirmation' => $request['password_confirmation'],
424:             'sex'                   => $request['sex'],
425:         ); 
426:         $userRules = array(
427:             'email'                 => 'required|email',
428:             'phone_number'          => 'required|numeric|digits:10',
429:             'firstname'             => 'required',
430:             'lastname'              => 'required',
431:             'password'              => 'min:4',
432:             'password_confirmation' => 'min:4',
433:             'sex'                   => 'required|in:man,vrouw'
434:         );
435: 
436:         $driverData = array(
437:             'user_id'               => $id,
438:             'drivers_exp'           => $request['driver_exp'],
439:             'global_information'    => $request['global_information'],
440:             'taxi_id'               => $request['car']
441:         );
442: 
443:         Driver::where('user_id', '=', $id)->update($driverData);
444: 
445:         Taxi::where('driver_id','=', $driver->id)->update(array('driver_id' => '0'));
446:         Taxi::where('id','=',$request['car'])->update(array('driver_id' => $driver->id));
447: 
448:         $validator = Validator::make($userData, $userRules);
449:         if ($validator->fails()){
450:             return redirect('chauffeurwijzigen/'.$id)->withErrors($validator)->withInput($userData);
451:         }
452:        
453:         if (empty($userData['password']) || empty($userData['password_confirmation'])) {
454:             array_forget($userData, 'password');
455:             array_forget($userData, 'password_confirmation');
456:         }
457: 
458:         if (array_key_exists('password', $userData)) {
459:             $userData['password'] = Hash::make($userData['password']);
460:             array_forget($userData, 'password_confirmation');
461:         } else {
462:             User::where('id', '=', $id)->update($userData);
463:             $this->upload($request, $id);
464:             $request->session()->flash('alert-success', 'Uw account is gewijziged, er zijn geen wijzigingen aan het wachtwoord doorgevoerd.');
465:             return redirect('/chauffeurs');
466:         }
467:        
468:         User::where('id', '=', $id)->update($userData);
469:         $request->session()->flash('alert-success', 'Uw account is gewijziged.');
470:         $this->upload($request, $id);
471:         return redirect('/chauffeurs');
472:         
473:     }
474: 
475:     /**
476:      * @authors Stefano Groenland, Richard Perdaan
477:      * @param Request $request
478:      * @param $id
479:      * @param $redirect
480:      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
481:      *
482:      * Grabs the file named 'profile_photo' from the request and uploads it onto the server,
483:      * It updates the corresponding user with the link to the uploaded picture as their profile_photo in the User table.
484:      */
485:     public function upload(Request $request , $id, $redirect = 0){
486:         $x = $request['x'];
487:         $y = $request['y'];
488:         $h = $request['h'];
489:         $w = $request['w'];
490: 
491:         $file = array('profile_photo' => $request->file('profile_photo'));
492:         $rules = array('profile_photo' => 'required|mimes:jpeg,bmp,png,jpg',);
493:         $validator = Validator::make($file, $rules);
494:         if ($validator->fails()) {
495:             if ($file) {
496:                 //$request->session()->flash('alert-danger', 'U heeft geen bestand / geen geldig bestand gekozen om te uploaden, voeg een foto toe.');
497:             }
498:             return redirect('/chauffeurtoevoegen');
499:         } else {
500:             if ($request->file('profile_photo')->isValid()) {
501:                 
502:                 $destinationPathOrigineel = 'assets/uploads/profiel/origineel';
503:                 $destinationPathThumb = 'assets/uploads/profiel/thumb';
504: 
505: 
506:                 $extension = $request->file('profile_photo')->getClientOriginalExtension();
507:                 $name = $request->file('profile_photo')->getClientOriginalName();
508:                 $fileName = rand(1111, 9999) .$name;
509: 
510:                 $request->file('profile_photo')->move($destinationPathOrigineel, $fileName);
511: 
512:                 File::copy($destinationPathOrigineel . '/' . $fileName, $destinationPathThumb . '/' . $fileName);
513: 
514:                 $ava = $destinationPathThumb . '/' . $fileName;
515:               
516:                 $crop = Image::make($ava)->fit(149)->crop($w, $h, $x, $y)->save();
517:                 $final = $destinationPathThumb . '/' . $crop->basename;
518:               
519:                 User::uploadPicture($id, $fileName);
520:                 if($redirect != 0){
521:                     $request->session()->flash('alert-success', 'Medewerker toegevoegd');
522:                     return redirect('/admins');
523:                 }else{
524:                     $request->session()->flash('alert-success', 'Chauffeur toegevoegd');
525:                     return redirect('/chauffeurs');
526:                 }
527: 
528:             } else {
529:                 $request->session()->flash('alert-danger', 'Er is een fout opgetreden tijdens het uploaden van uw bestand.');
530: 
531:                 if($redirect != 1){
532:                     return redirect('/admins');
533:                 }elseif($redirect == 2){
534:                     return redirect('/profielwijzigen#tab_1_2');
535:                 }
536:                 else{
537:                     return redirect('/chauffeurs');
538:                 }
539:             }
540:         }
541:     }
542: 
543:     /**
544:      * @author Stefano Groenland
545:      * @param Request $request
546:      * @return \Illuminate\Http\RedirectResponse
547:      *
548:      * Gets values from the $request, validates the input on specific rules.
549:      * If all passes it will Create an Tablet account with a link of the tablet and taxi.
550:      */
551:     public function addTablet(Request $request){
552: 
553:         $userData = array(
554:             'user_rank'     =>  'tablet',
555:             'tablet_name'   =>  $request['tablet'],
556:             'email'         =>  str_random(15)
557:         );
558:         $userRules = array(
559:             'tablet_name'   =>  'required|max:50|unique:user'
560:         );
561:         $valid = Validator::make($userData,$userRules);
562:         if($valid->fails()){
563:             return redirect('tablettoevoegen')->withErrors($valid)->withInput($userData);
564:         }
565:         $user = User::create($userData);
566: 
567:         $tabData = array(
568:             'taxi_id'   =>  $request['taxi'],
569:             'user_id'   =>  $user->id
570:         );
571:         Tablet::create($tabData);
572: 
573:         $request->session()->flash('alert-success', 'De tablet is toegevoegd.');
574:         return redirect()->route('tablets');
575:     }
576: 
577:     /**
578:      * @author Stefano Groenland
579:      * @param Request $request
580:      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
581:      *
582:      * Gets the ID of the route parameter, and grabs all information for a tablet with that id,
583:      * aswell as getting data from the $request and changes the linked rows with the values of the requests after validation.
584:      */
585:     public function editTablet(Request $request){
586:         $id = Route::current()->getParameter('id');
587:         $tablet = Tablet::where('id',$id)->first();
588:         $user = User::where('id',$tablet->user_id)->first();
589: 
590:         $tabUserData = array(
591:             'tablet_name'   => trim($request['tablet']),
592:             'taxi_id'   => $tablet->taxi_id
593:         );
594:         $tabUserRules = array(
595:             'tablet_name'   => 'required|max:50|unique:user,tablet_name,' . $user->id
596:         );
597:         $valid = Validator::make($tabUserData, $tabUserRules);
598:         if($valid->fails()){
599:             return redirect('tabletwijzigen/'.$id)->withErrors($valid)->withInput($tabUserData);
600:         }
601:         array_forget($tabUserData, 'taxi_id');
602:         $user->update($tabUserData);
603:         $tablet->update(['taxi_id' => $request['taxi']]);
604: 
605:         $request->session()->flash('alert-success', 'Tablet '. $request['tablet'] .' is gewijziged.');
606:         return redirect('/tablets');
607:     }
608: 
609:     /**
610:      * @author Stefano Groenland
611:      * @return \Illuminate\Http\RedirectResponse
612:      *
613:      * Grabs the ID of the route, And deletes the corresponding rows from the Database.
614:      */
615:     public function deleteTablet(){
616:         $id = Route::current()->getParameter('id');
617: 
618:         $tablet = Tablet::where('id',$id)->first();
619:         $user = User::where('id',$tablet->user_id)->first();
620:         Tablet::where('id',$id)->delete();
621:         User::where('id',$tablet->id)->delete();
622: 
623:         session()->flash('alert-success', 'Tablet '.$user->tablet_name .' verwijderd.');
624:         return redirect()->route('tablets');
625:     }
626: 
627:     /**
628:      * @author Stefano Groenland
629:      * @param Request $request
630:      * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
631:      *
632:      * Grabs the ID from the route, looks for an user with the given ID and edits it with the requests values if they passes the validation.
633:      */
634:     public function editProfile(Request $request){
635:         $id = Route::current()->getParameter('id');
636: 
637:         $user = User::where('id',$id)->first();
638: 
639:         $data = array(
640:             'firstname'                 =>  $request['firstname'],
641:             'lastname'                  =>  $request['lastname'],
642:             'phone_number'              =>  $request['phone_number'],
643:             'email'                     =>  $request['email'],
644:             'password'                  =>  $request['password'],
645:             'password_confirmation'     =>  $request['password_confirmation']
646:         );
647:         $rules = array(
648:             'firstname'             =>  'required|min:4|max:50',
649:             'lastname'              =>  'required|min:4|max:50',
650:             'phone_number'          =>  'required|numeric|digits:10',
651:             'email'                 =>  'required|email|unique:user,email,' . $user->id,
652:             'password'              =>  'min:4|confirmed',
653:             'password_confirmation' =>  'min:4'
654:         );
655: 
656:         $valid = Validator::make($data, $rules);
657:         if($valid->fails()){
658:             return redirect('/profielwijzigen')->withErrors($valid)->withInput($data);
659:         }
660:         if(!empty($data['password']) && !empty($data['password_confirmation'])){
661:             array_forget($data,'password_confirmation');
662:             $data['password'] = Hash::make($data['password']);
663:         }else{
664:             array_forget($data,'password');
665:             array_forget($data,'password_confirmation');
666:         }
667: 
668: 
669:         $user->update($data);
670: 
671:         $request->session()->flash('alert-success', 'Uw profiel is gewijziged.');
672:         return redirect('/profielwijzigen');
673:     }
674: 
675:     /**
676:      * @author Stefano Groenland
677:      * @param Request $request
678:      * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
679:      *
680:      * Grabs the ID from the route, checks if the given values are validated and changes the users password if they do.
681:      */
682:     public function editPassword(Request $request){
683:         $id = Route::current()->getParameter('id');
684:         $user = User::where('id',$id)->first();
685:         $data = array(
686:             'password'                  =>  $request['password'],
687:             'password_confirmation'     =>  $request['password_confirmation']
688:         );
689:         $rules = array(
690:             'password'              =>  'required|min:4|confirmed',
691:             'password_confirmation' =>  'required|min:4'
692:         );
693: 
694:         $valid = Validator::make($data,$rules);
695:         if($valid->fails()){
696:             return redirect('/profielwijzigen#tab_1_3')->withErrors($valid);
697:         }
698:         array_forget($data,'password_confirmation');
699:         $data['password'] = Hash::make($data['password']);
700: 
701:         $user->update($data);
702:         $request->session()->flash('alert-success', 'Uw wachtwoord is gewijziged.');
703:         return redirect('/profielwijzigen#tab_1_3');
704:     }
705: 
706:     /**
707:      * @author Stefano Groenland
708:      * @param Request $request
709:      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
710:      *
711:      * Grabs the ID of the route, looks for the useracount with the given ID and changes the profile picture of it.
712:      * It also deletes the past profile picture with the unlink() function.
713:      */
714:     public function editProfilePhoto(Request $request){
715: 
716:         $id = Route::current()->getParameter('id');
717:         $find = User::find($id);
718:         if(!empty($find->profile_photo)) {
719:             unlink("assets/uploads/profiel/thumb/".$find->profile_photo);
720:             unlink("assets/uploads/profiel/origineel/".$find->profile_photo);
721:         }
722:         $this->upload($request,$id,2);
723:         $request->session()->flash('alert-success', 'Uw profielfoto is gewijzigd');
724:         return redirect('/profielwijzigen');
725:     }
726: }
727: 
728: 
APIv1 API documentation generated by ApiGen