Example #1
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->session()->has('current_property')) {
         if (Auth::user()->role->name == 'admin') {
             $properties = Property::all();
             if ($properties->count() > 0) {
                 Auth::user()->properties()->sync($properties);
                 $request->session()->put('current_property', $properties[0]);
             }
         } else {
             $property = Property::findOrFail(Auth::user()->default_property);
             $request->session()->put('current_property', $property);
         }
     }
     if (!$request->session()->has('available_properties')) {
         if (count(Auth::user()->properties) > 1) {
             $request->session()->put('available_properties', Auth::user()->properties);
         }
     }
     if ($request->has('current_property')) {
         $property = Property::find($request->get('current_property'));
         if ($property !== null) {
             $request->session()->put('current_property', $property);
         }
     }
     return $next($request);
 }
Example #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id, Request $request)
 {
     $property = Property::findOrFail($id);
     $message = "";
     try {
         $property->delete();
         $property->removeLogo();
         $message = trans('appstrings.item_removed', ['item' => $property->name]);
         Session::flash('message_type', 'success');
     } catch (\PDOException $e) {
         $message = trans('sqlmessages.' . $e->getCode());
         if ($message == 'sqlmessages.' . $e->getCode()) {
             $message = trans('sqlmessages.undefined');
         }
         if ($request->ajax()) {
             return ['code' => 'error', 'message' => $message];
         }
         Session::flash('message_type', 'error');
     }
     $request->session()->forget('current_property');
     if ($request->ajax()) {
         return ['code' => 'ok', 'message' => $message];
     }
     Session::flash('message', $message);
     return redirect()->route('admin.property.index');
 }