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 Illuminate\Http\Request;
  6: 
  7: use App\Http\Requests;
  8: use App\Http\Controllers\Controller;
  9: use App\Comment;
 10: use App\Driver;
 11: use Route, View;
 12: use Illuminate\Support\Facades\Auth;
 13: use Illuminate\Support\Facades\Validator;
 14: 
 15: 
 16: class CommentController extends Controller
 17: {
 18:     /**
 19:      * @author Stefano Groenland
 20:      * @return mixed
 21:      *
 22:      * Gets 2 objects from the databases and passes them along with the view when making the view.
 23:      */
 24:     public function showComment(){
 25:         $comments = Comment::with('driver')->where('approved','!=',1)->get();
 26: 
 27: 
 28:         $driver = Driver::with('user')->where('user_id',Auth::user()->id)->first();
 29: 
 30:         if(Auth::user()->user_rank == 'admin'){
 31:             $commentsApproved = Comment::with('driver')->where('approved','=',1)->get();
 32:         }else{
 33:             $commentsApproved = Comment::with('driver')->where('approved','=',1)->where('driver_id',$driver->id)->get();
 34:         }
 35: 
 36:         foreach($commentsApproved as $comment){
 37:             if($driver){
 38:                 $comment->where('driver_id',$driver->id)->update(['seen' => 1]);
 39:             }
 40:         }
 41: 
 42:         return View::make('/opmerkingen', compact('comments','commentsApproved'));
 43:     }
 44: 
 45:     /**
 46:      * @author Stefano Groenland
 47:      * @return mixed
 48:      *
 49:      * Gets all comments where column 'approved' = 1.
 50:      */
 51:     public function showCommentsApproved(){
 52:         $commentsApproved = Comment::with('driver')->where('approved','=',1)->get();
 53:         return View::make('/opmerkingen-verwerkt', compact('comments','commentsApproved'));
 54:     }
 55: 
 56:     /**
 57:      * @author Stefano Groenland
 58:      * @return mixed
 59:      *
 60:      * Grabs the route parameter ID, Looks for a comment row with that ID and passes them along,
 61:      * when making the 'opmerkingwijzigen view'
 62:      */
 63:     public function showCommentEdit(){
 64:         $id = Route::current()->getParameter('id');
 65:         $comment = Comment::with('driver')->where('id',$id)->first();
 66:         return View::make('/opmerkingwijzigen',compact('comment','id'));
 67:     }
 68: 
 69:     /**
 70:      * @author Stefano Groenland
 71:      * @param Request $request
 72:      * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
 73:      *
 74:      * Gets the ID of the route parameter, and grabs all information for a comment row with that ID,
 75:      * aswell as getting data from the $request and changes the linked row with the values of the requests after validation.
 76:      */
 77:     public function editComment(Request $request){
 78:         $id = Route::current()->getParameter('id');
 79:         $comment = Comment::where('id',$id)->first();
 80:         if($comment->approved == 0){
 81:             $redir = 1;
 82:         }else{
 83:             $redir = 0;
 84:         }
 85:         $data = array(
 86:             'comment'   =>  $request['comment'],
 87:             'approved'  =>  $request['approved']
 88:         );
 89:         $rules = array(
 90:             'comment'   =>  'required|max:255'
 91:         );
 92:         $valid = Validator::make($data,$rules);
 93:         if($valid->fails()){
 94:             return redirect('opmerkingwijzigen/'.$id)->withErrors($valid)->withInput($data);
 95:         }
 96:         $comment->update($data);
 97:         $request->session()->flash('alert-success', 'Opmerking '. $request['name'] .' is gewijziged.');
 98: 
 99:         if($redir == 1){
100:             return redirect('/opmerkingen');
101:         }
102:         return redirect('/opmerkingen/verwerkt');
103: 
104: 
105:     }
106: 
107:     /**
108:      * @author Stefano Groenland
109:      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
110:      *
111:      * Looks for a row with the passed ID , upon finding it checks what the 'approved' value is,
112:      * when it's not approved it will be set to approved, and if it's approved it will be set to not approved.
113:      */
114:     public function togglesStateComment(){
115:         $id     = Route::current()->getParameter('id');
116:         $redir  = Route::current()->getParameter('redir');
117:         $msg    = Comment::where('id',$id)->first();
118:         if(!$msg->approved > 0){
119:             $msg->where('id',$id)->update(['approved' => 1]);
120:         }else{
121:             $msg->where('id',$id)->update(['approved' => 0]);
122:         }
123:         session()->flash('alert-success', 'Opmerking status aangepast.');
124:         if($redir < 1){
125:             return redirect('/opmerkingen');
126:         }else{
127:             return redirect('/opmerkingen/verwerkt');
128:         }
129: 
130:     }
131: 
132:     /**
133:      * @author Stefano Groenland
134:      * @return \Illuminate\Http\RedirectResponse
135:      *
136:      * Grabs the ID of the route, And deletes the corresponding row from the Database.
137:      */
138:     public function deleteComment(){
139:         $id = Route::current()->getParameter('id');
140: 
141:         $comment = Comment::where('id',$id)->first();
142:         $comment->delete();
143:         session()->flash('alert-success', 'Commentaar verwijderd.');
144:         return redirect()->route('opmerkingen');
145:     }
146: 
147: }
APIv1 API documentation generated by ApiGen