예제 #1
0
 public function postCreate(Request $request)
 {
     #dump($request);
     #sub_species must actually be an animal, not a "pick a type"
     $this->validate($request, ['name' => 'required', 'sub_species' => 'required', 'sex' => 'required', 'enclosure' => 'required']);
     # Enter book into the database
     $animal = new \CareCats\Animal();
     $animal->name = $request->name;
     $animal->sub_species = $request->sub_species;
     $animal->sex = $request->sex;
     $animal->bio = $request->bio;
     $animal->enclosure = $request->enclosure;
     $animal->birth_date = $request->birth_date;
     $animal->care_date = $request->care_date;
     $animal->save();
     # Done
     \Session::flash('flash_message', 'Your animal was added!');
     return redirect('/animals');
 }
예제 #2
0
            $animal->sub_species = 'lion';
            # Save the changes
            $animal->save();
        }
        echo "Update complete; check the database to see if your update worked...";
    } else {
        echo "Animals not found, can't update.";
    }
});
Route::get('/modelCat', function () {
    $animal = new \CareCats\Animal();
    $animal->name = 'Ace';
    $animal->sex = 'male';
    $animal->sub_species = 'jaguar';
    $animal->enclosure = 'J';
    $animal->save();
    dump($animal->toArray());
    $procedure = new \CareCats\Procedure();
    $procedure->title = "Hates Derek";
    $procedure->symptoms = "grumpy around derek";
    $procedure->comments = "nothing to do!";
    $procedure->animal()->associate($animal);
    # <--- Associate the author with this procedure
    $procedure->save();
    dump($procedure->toArray());
});
Route::get('/modelQuery', function () {
    $procedure = \CareCats\Procedure::first();
    dump($procedure->toArray());
    # Get the animal from this procedure using the "animal" dynamic property
    # "animal" corresponds to the the relationship method defined in the procedure model