コード例 #1
0
ファイル: SpeciesTableSeeder.php プロジェクト: sjmrt/blog.dev
 public function run()
 {
     $species1 = new Species();
     $species1->species = 'dog';
     $species1->save();
     $species2 = new Species();
     $species2->species = 'cat';
     $species2->save();
 }
コード例 #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Species();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Species'])) {
         $model->attributes = $_POST['Species'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
コード例 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (!empty(Input::get('name'))) {
         $val = Species::validate(Input::all());
         if ($val->fails()) {
             return Redirect::back()->withErrors($val);
         }
         try {
             $species = new Species();
             $species->name = Input::get('name');
             $species->save();
         } catch (Exception $e) {
             return Redirect::back()->with('message', FlashMessage::DisplayAlert('Species can NOT be created. Already exists.', 'alert'));
         }
         return Redirect::back()->with('message', FlashMessage::DisplayAlert('Species Created Successfully!', 'success'));
     }
     return Redirect::back()->with('message', FlashMessage::DisplayAlert('Enter a valid species name.', 'alert'));
 }
コード例 #4
0
 function test_find()
 {
     //Arrange
     $name = "naked mole rat";
     $fur = 0;
     $wings = 0;
     $legs = 4;
     $test_species = new Species($name, $fur, $wings, $legs);
     $test_species->save();
     //Act
     $result = Species::find("naked mole rat");
     //Assert
     $this->assertEquals($test_species, $result);
 }