public static function getRandTip() { $tips = Cache::remember(self::CACHE_KEY, self::CACHE_MINUTES, function () { return Tip::all(); }); return $tips->random(); }
/** * Setup the layout used by the controller. * * @return void */ protected function setupLayout() { if (!is_null($this->layout)) { $this->layout = View::make($this->layout); } View::share('currentUser', Auth::user()); View::share('siteStat', App::make('Phphub\\Stat\\Stat')->getSiteStat()); View::share('siteTip', Tip::getRandTip()); }
/** * Setup the layout used by the controller. * * @return void */ protected function setupLayout() { if (!is_null($this->layout)) { $this->layout = View::make($this->layout); } View::share('currentUser', Auth::user()); View::share('siteStat', App::make('Phphub\\Stat\\Stat')->getSiteStat()); View::share('siteTip', Tip::getRandTip()); View::share('g_sideInfos', Topic::getSideInfos(5)); View::share('links', Link::remember(1440)->get()); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $types = Type::all(); $types->toarray(); $tips = Tip::all(); $tips->toarray(); $breeds = Breed::all(); $breeds->toarray(); // $tips = DB::table('pet_tips') // ->where('breed_id', '=', $breed_id) // ->get(); return View::make('tips.tips', compact('types', 'breeds', 'tips')); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $about = ""; $this->response['console'] = "SERVER[status]-> OK::200\n "; $this->response['console'] .= "\t" . Input::get('action') . "\n"; switch (Input::get('action')) { case 'new_admin': $this->response['console'] .= "Creating new admin...\n"; $mUser = new User(); $mUser->username = Input::get('username'); $mUser->password = Hash::make(Input::get('password')); $mUser->role = Input::get('role'); $mUser->save(); $this->response['message'] = ucfirst($mUser->username) . " was added to admins successfully"; break; case 'new_medicine_type': $this->response['console'] .= "Creating new medicine type...\n"; $mType = new Type(); $mType->type = Input::get('type'); $mType->save(); $this->response['message'] = ucfirst($mType->type) . " was added to medicine types successfully"; break; case 'new_medicine_breed': $this->response['console'] .= "Creating new medicine breed...\n"; $mBreed = new Breed(); $mBreed->breed = Input::get('breed'); $mBreed->type_id = Input::get('type'); $this->response['console'] = $mBreed->breed . " | " . $mBreed->type_id . "\n"; $mBreed->save(); $this->response['message'] = ucfirst($mBreed->breed) . " was added to medicine breeds successfully"; break; case 'new_medicines_tip': $_about = Input::get('about'); $this->response['console'] .= "Creating new medicine tip...\n"; $this->response['console'] .= "about :" + $_about + " \n"; if ($_about == "1") { $about = "Health"; } elseif ($_about == "2") { $about = "Food"; } else { $about = "Dosage"; } $mTip = new Tip(); $mTip->type_id = Input::get('type'); $mTip->breed_id = Input::get('breed'); $mTip->about = $about; $mTip->content = Input::get('content'); $this->response['console'] .= $mTip->type_id . " | " . $mTip->breed_id . " | " . $mTip->about . " | " . $mTip->content; $mTip->save(); $this->response['message'] = "New tip was successfully recorded"; break; case 'new_medicine': $this->response['console'] .= "Creating new medicine process has started\n"; $mPet = new Pet(); if (Input::hasFile('photo')) { $uploadDir = public_path() . "/img/uploads/"; $this->response['console'] .= "\tNew image process has started\n"; $fileName = sha1(Input::get('name')) . "." . Input::get('ext'); $_FILES['photo']['name'] = $fileName; $this->response['console'] .= "\ttmp_name: " . $_FILES['photo']['tmp_name'] . "\n"; $this->response['console'] .= "\tsaving to " . $uploadDir . "\n"; move_uploaded_file($_FILES["photo"]["tmp_name"], $uploadDir . $_FILES["photo"]["name"]); $mPet->image = $fileName; } $mPet->name = Input::get('name'); $mPet->breed_id = Input::get('breed'); $mPet->appearance_id = Input::get('appearance'); $mPet->type_id = Input::get('type'); $mPet->age = Input::get('age'); $mPet->price = Input::get('price'); $mPet->description = Input::get('description'); $mPet->care = Input::get('care'); $mPet->save(); $this->response['message'] = "{$mPet->name} was added to the list of medicines successfully"; } return json_encode($this->response); }