Exemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::create();
     $animal_id = \CareCats\Animal::where('sub_species', '=', 'tiger')->pluck('id');
     DB::table('procedures')->insert(['created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString(), 'date' => $faker->date($format = 'Y-m-d', $max = 'now'), 'animal_id' => $animal_id, 'title' => 'Tooth Extraction', 'symptoms' => "Unwillingness to eat, poor temperment", 'comments' => 'took 1 hour, successful!']);
     $animal_id = \CareCats\Animal::where('sub_species', '=', 'lion')->pluck('id');
     DB::table('procedures')->insert(['created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString(), 'date' => $faker->date($format = 'Y-m-d', $max = 'now'), 'animal_id' => $animal_id, 'title' => 'Eye removal', 'symptoms' => "Failing eyesite, poor temperment", 'comments' => 'took 3 hours, successful!']);
     $animal_id = \CareCats\Animal::where('sub_species', '=', 'bobcat')->pluck('id');
     DB::table('procedures')->insert(['created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString(), 'date' => $faker->date($format = 'Y-m-d', $max = 'now'), 'animal_id' => $animal_id, 'title' => 'Wound suture', 'symptoms' => "Open wound, seeping, bloody", 'comments' => 'took 2 hours, successful!']);
     $animal_id = \CareCats\Animal::where('sub_species', '=', 'cougar')->pluck('id');
     DB::table('procedures')->insert(['created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString(), 'date' => $faker->date($format = 'Y-m-d', $max = 'now'), 'animal_id' => $animal_id, 'title' => 'Lethargy', 'symptoms' => "General malaise, little movement", 'comments' => 'Brought inside, kept under observation for two days']);
     $animal_id = \CareCats\Animal::where('sub_species', '=', 'leopard')->pluck('id');
     DB::table('procedures')->insert(['created_at' => \Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => \Carbon\Carbon::now()->toDateTimeString(), 'date' => $faker->date($format = 'Y-m-d', $max = 'now'), 'animal_id' => $animal_id, 'title' => 'Arthritis', 'symptoms' => "stiff and achy", 'comments' => 'Brought inside on the recent cold days, given movies to watch and treats and blankets']);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     # First, create an array of all the books we want to associate tags with
     # The *key* will be the book title, and the *value* will be an array of tags.
     //    $books =[
     //        'The Great Gatsby' => ['novel','fiction','classic','wealth'],
     //        'The Bell Jar' => ['novel','fiction','classic','women'],
     //        'I Know Why the Caged Bird Sings' => ['autobiography','nonfiction','classic','women']
     //    ];
     # First, create an array of all the animals we want to associate sponsors with
     # The *key* will be the animal name, and the *value* will be an array of sponsor first_names.
     $animal_model1 = DB::table('animals')->where('id', '=', 1)->first();
     $animal_model2 = DB::table('animals')->where('id', '=', 2)->first();
     $animal_model3 = DB::table('animals')->where('id', '=', 3)->first();
     $animal_model4 = DB::table('animals')->where('id', '=', 4)->first();
     $animal_model5 = DB::table('animals')->where('id', '=', 5)->first();
     $animal1 = $animal_model1->name;
     $animal2 = $animal_model2->name;
     $animal3 = $animal_model3->name;
     $animal4 = $animal_model4->name;
     $animal5 = $animal_model5->name;
     $sponsor_model1 = DB::table('sponsors')->where('id', '=', 1)->first();
     $sponsor_model2 = DB::table('sponsors')->where('id', '=', 2)->first();
     $sponsor_model3 = DB::table('sponsors')->where('id', '=', 3)->first();
     $sponsor_model4 = DB::table('sponsors')->where('id', '=', 4)->first();
     $sponsor_model5 = DB::table('sponsors')->where('id', '=', 5)->first();
     $sponsor1 = $sponsor_model1->first_name;
     $sponsor2 = $sponsor_model2->first_name;
     $sponsor3 = $sponsor_model3->first_name;
     $sponsor4 = $sponsor_model4->first_name;
     $sponsor5 = $sponsor_model5->first_name;
     $animals = [$animal1 => [$sponsor1, $sponsor2, $sponsor3, $sponsor4], $animal2 => [$sponsor2, $sponsor3, $sponsor4, $sponsor5], $animal3 => [$sponsor3, $sponsor4, $sponsor5, $sponsor1], $animal4 => [$sponsor4, $sponsor5, $sponsor1, $sponsor2], $animal5 => [$sponsor5, $sponsor1, $sponsor2, $sponsor3]];
     # Now loop through the above array, creating a new pivot for each book to tag
     // foreach($books as $title => $tags) {
     foreach ($animals as $name => $sponsors) {
         # First get the book
         // $book = \App\Book::where('title','like',$title)->first();
         $animal = \CareCats\Animal::where('name', 'like', $name)->first();
         # Now loop through each tag for this book, adding the pivot
         // foreach($tags as $tagName) {
         foreach ($sponsors as $sponsorName) {
             //$tag = \App\Tag::where('name','LIKE',$tagName)->first();
             $sponsor = \CareCats\Sponsor::where('first_name', 'LIKE', $sponsorName)->first();
             # Connect this tag to this book
             //$book->tags()->save($tag);
             $animal->sponsors()->save($sponsor);
         }
     }
 }
Exemplo n.º 3
0
Route::get('/sponsorCat', function () {
    // $book = \App\Book::where('title','=','The Great Gatsby')->first();
    //
    // echo $book->title.' is tagged with: ';
    // foreach($book->tags as $tag) {
    //     echo $tag->name.' ';
    // }
    $animal = \CareCats\Animal::where('name', '=', 'Matt')->first();
    echo '<br /><br />' . $animal->name . ' is sponsored by: ';
    foreach ($animal->sponsors as $sponsor) {
        echo $sponsor->first_name . ', ';
    }
});
Route::get('/sponsorCat2', function () {
    #eagerly loaded
    $animals = \CareCats\Animal::with('sponsors')->get();
    foreach ($animals as $animal) {
        echo '<br>' . $animal->name . ' is sponsored by: ';
        foreach ($animal->sponsors as $sponsor) {
            echo $sponsor->first_name . ', ';
        }
    }
});
# Show login form
Route::get('/login', 'Auth\\AuthController@getLogin');
# Process login form
Route::post('/login', 'Auth\\AuthController@postLogin');
# Process logout
Route::get('/logout', 'Auth\\AuthController@getLogout');
# Show registration form
Route::get('/register', 'Auth\\AuthController@getRegister');
Exemplo n.º 4
0
 public function postEdit(Request $request)
 {
     // $messages = [
     //     'not_in' => 'You have to choose an author.',
     // ];
     $this->validate($request, ['name' => 'required', 'sub_species' => 'required', 'sex' => 'required', 'enclosure' => 'required']);
     // $uploads_dir = public_path();
     // $uploads_dir .= '/downloads';
     //
     // $upload_file = $uploads_dir . basename($_FILES["fileToUpload"]["name"]);
     // $uploadOk = 1;
     // $target_dir = "uploads/";
     // $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
     // $uploadOk = 1;
     // $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
     // // Check if image file is a actual image or fake image
     // if(isset($_POST["submit"])) {
     //     $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
     //     if($check !== false) {
     //         echo "File is an image - " . $check["mime"] . ".";
     //         $uploadOk = 1;
     //     } else {
     //         echo "File is not an image.";
     //         $uploadOk = 0;
     //     }
     // }
     $animal = \CareCats\Animal::find($request->id);
     $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();
     \Session::flash('flash_message', 'Your changes were saved.');
     return redirect('/animal/edit/' . $request->id);
 }