/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $breed = Input::all();
     $val = Breed::validate($breed);
     if ($val->fails()) {
         return Redirect::back()->withErrors($val);
     }
     try {
         $b = new Breed();
         $b->name = Input::get('name');
         $b->species_id = Input::get('species_id');
         $b->save();
     } catch (Exception $e) {
         return Redirect::back()->with('message', FlashMessage::DisplayAlert('Cannot Save Breed. Already Exists!', 'alert'));
     }
     return Redirect::back()->with('message', FlashMessage::DisplayAlert('Breed created succesfully!.', 'success'));
 }
 /**
  * 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);
 }
Example #3
0
        }
        redirect_head(ROOT_URL . "admin/manage_breeds.php");
    }
    /* If Pet_Type is being added */
    if (isset($_POST["add_pet_type"])) {
        $new_pet_type = new Pet_Type();
        $new_pet_type->name = $_POST["name"];
        if ($new_pet_type->save()) {
            // get the new pet type's wk
            $new_wk = $database->insert_id();
            $session->message($session->message . "The new pet type {$new_pet_type->name} was successfully created!<br />");
            // create an undefined breed for the new pet type
            $undefined_breed = new Breed();
            $undefined_breed->name = "undefined";
            $undefined_breed->pet_type_wk = $new_wk;
            if ($undefined_breed->save()) {
                $session->message($session->message . "New undefined breed created for new pet type.<br />");
            } else {
                //die($database->last_error);
                $session->message($session->message . "Creation of undefined breed for new pet type was unsuccessful.<br />");
            }
            redirect_head(current_url());
        } else {
            $session->message("The new pet type was not successfully created. Please try again.<br />");
            redirect_head(current_url());
        }
    }
}
//header template
require_once "../requires/template/header.php";
// Add new pet type