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\Newspaper;
  6: use Illuminate\Http\Request;
  7: 
  8: use App\Http\Requests;
  9: use App\Http\Controllers\Controller;
 10: use Illuminate\Support\Facades\Validator;
 11: use Route, View;
 12: use Image as Image;
 13: class NewspaperController extends Controller
 14: {
 15: 
 16:     /**
 17:      * @author Stefano Groenland
 18:      * @return mixed
 19:      *
 20:      * Grabs all newspapers from the database and passes them along when making the view.
 21:      */
 22:     public function showNews(){
 23:         $news   = Newspaper::all();
 24:         return View::make('/nieuws', compact('news'));
 25:     }
 26: 
 27:     /**
 28:      * @author Stefano Groenland
 29:      * @return mixed
 30:      *
 31:      * Makes the 'nieuwstoevoegen' view.
 32:      */
 33:     public function showNewsAdd(){
 34:         return View::make('/nieuwstoevoegen');
 35:     }
 36: 
 37:     /**
 38:      * @author Stefano Groenland
 39:      * @return mixed
 40:      *
 41:      * Grabs the route parameter ID, Looks for a news row with that ID and passes them along,
 42:      * when making the 'nieuwswijzigen view'
 43:      */
 44:     public function showNewsEdit(){
 45:         $id     = Route::current()->getParameter('id');
 46:         $news   = Newspaper::where('id',$id)->first();
 47:         return View::make('/nieuwswijzigen', compact('news','id'));
 48:     }
 49: 
 50:     /**
 51:      * @author Stefano Groenland
 52:      * @param Request $request
 53:      * @return $this|\Illuminate\Http\RedirectResponse
 54:      *
 55:      * Gets values from the $request, validates the input on specific rules.
 56:      * If all passes it will Create a row for a news group with with the rss feed link and a name.
 57:      */
 58:     public function addNews(Request $request){
 59:         $data = array(
 60:             'name'              =>  $request['name'],
 61:             'link'              =>  $request['link']
 62:         );
 63:         $rules = array(
 64:             'name'  =>  'required|max:50',
 65:             'link'  =>  'required'
 66:         );
 67: 
 68:         $valid = Validator::make($data,$rules);
 69:         if($valid->fails()){
 70:             return redirect()->route('nieuws')->withErrors($valid)->withInput($data);
 71:         }
 72:         $news = Newspaper::create($data);
 73:         $this->upload($request,$news->id);
 74: 
 75:         $request->session()->flash('alert-success', 'Nieuwsgroep '.$news->name.' is toegevoegd.');
 76:         return redirect()->route('nieuws');
 77: }
 78: 
 79:     /**
 80:      * @author Stefano Groenland
 81:      * @param Request $request
 82:      * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
 83:      *
 84:      * Gets the ID of the route parameter, and grabs all information for a news row with that ID,
 85:      * aswell as getting data from the $request and changes the linked row with the values of the requests after validation.
 86:      */
 87:     public function editNews(Request $request){
 88:         $id = Route::current()->getParameter('id');
 89: 
 90:         $news = Newspaper::where('id',$id)->first();
 91:         $data = array(
 92:             'name'  =>  $request['name'],
 93:             'link'  =>  $request['link']
 94:         );
 95:         $rules = array(
 96:             'name'  =>  'required|max:50',
 97:             'link'  =>  'required'
 98:         );
 99:         $valid = Validator::make($data,$rules);
100:         if($valid->fails()){
101:             return redirect('nieuwswijzigen/'.$id)->withErrors($valid)->withInput($data);
102:         }
103: 
104:         $news->update($data);
105:         $this->upload($request,$news->id);
106:         $request->session()->flash('alert-success', 'Nieuwsgroep '. $request['name'] .' is gewijziged.');
107:         return redirect('/nieuws');
108:     }
109: 
110:     /**
111:      * @author Stefano Groenland
112:      * @return \Illuminate\Http\RedirectResponse
113:      *
114:      * Grabs the ID of the route, And deletes the corresponding row from the Database.
115:      */
116:     public function deleteNews(){
117:         $id = Route::current()->getParameter('id');
118: 
119:         $news = Newspaper::where('id',$id)->first();
120:         $news->delete();
121:         if(!$news->logo == ""){
122:             unlink($news->logo);
123:         }
124:         session()->flash('alert-success', 'Nieuwsgroep '.$news->name .' verwijderd.');
125:         return redirect()->route('nieuws');
126:     }
127: 
128:     /**
129:      * @authors Stefano Groenland
130:      * @param Request $request
131:      * @param $id
132:      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
133:      *
134:      * Grabs the file named 'logo' from the request and uploads it onto the server,
135:      * It updates the corresponding newspaper with the link to the uploaded picture as their logo in the Newspaper table.
136:      */
137:     public function upload(Request $request , $id){
138: 
139:         $x = $request['x'];
140:         $y = $request['y'];
141:         $h = $request['h'];
142:         $w = $request['w'];
143: 
144:         $file = array('logo' => $request->file('logo'));
145:         $rules = array('logo' => 'required|mimes:jpeg,bmp,png,jpg',);
146:         $validator = Validator::make($file, $rules);
147:         if ($validator->fails()) {
148:             if ($file) {
149:                 //$request->session()->flash('alert-danger', 'U heeft geen bestand / geen geldig bestand gekozen om te uploaden, voeg een foto toe.');
150:             }
151:             return redirect('/nieuws');
152:         } else {
153:             if ($request->file('logo')->isValid()) {
154:                 $destinationPath = 'assets/uploads';
155:                 $extension = $request->file('logo')->getClientOriginalExtension();
156:                 $fileName = rand(1111, 9999) . '.' . $extension;
157:                 $request->file('logo')->move($destinationPath, $fileName);
158:                 $ava = $destinationPath . '/' . $fileName;
159:                 $img = Image::make($ava)->fit(200)->crop($w, $h, $x, $y)->save();
160:                 $final = $destinationPath . '/' . $img->basename;
161: 
162:                 Newspaper::uploadPicture($id, $final);
163:                 return redirect('/nieuws');
164: 
165:             } else {
166:                 $request->session()->flash('alert-danger', 'Er is een fout opgetreden tijdens het uploaden van uw bestand.');
167:             }
168:         }
169: 
170:     }
171: 
172: }
173: 
APIv1 API documentation generated by ApiGen