/**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     if (\Request::input('filter')) {
         $filter = json_decode(\Request::input('filter'), true);
         for ($i = 0; $i < count($filter); $i++) {
             $field = $filter[$i]['property'];
             $value = $filter[$i]['value'];
             $operator = isset($filter[$i]['operator']) ? $filter[$i]['operator'] : null;
             $filterType = isset($filter[$i]['type']) ? $filter[$i]['type'] : null;
             switch ($filterType) {
                 case 'string':
                     $contact = contact::where($field, $operator, "%{$value}%");
                     $count = contact::where($field, $operator, "%{$value}%")->count();
                     break;
             }
         }
         return \Response::json(array('success' => true, 'contacts' => $contact->get()));
     } else {
         return \Response::json(array('success' => true, 'contacts' => Contact::get()));
     }
 }
Exemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $insert = $request->all();
     $safeName = false;
     //upload image
     if ($file = Input::file('image')) {
         $fileName = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = '/uploads/';
         $destinationPath = Config::get('app.path') . $folderName;
         $safeName = time() . "_" . str_random(10) . '.' . $extension;
         $file->move($destinationPath, $safeName);
         $insert['image'] = $safeName ? $folderName . $safeName : '';
     }
     if (isset(Contact::$boolean)) {
         foreach (contact::$boolean as $field) {
             if (isset($insert[$field]) && $insert[$field] == "on") {
                 $insert[$field] = 1;
             }
         }
     }
     contact::create($insert);
     return redirect('admin/contacts')->with('success', Lang::get('message.success.create'));
 }