protected function getCatsData()
 {
     $cats = Cat::with('breed')->get();
     foreach ($cats as $cat) {
         $output[] = [$cat->name, $cat->date_of_birth, $cat->breed->name];
     }
     return $output;
 }
Ejemplo n.º 2
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     //        $v = '<pre>'.print_r($cats, true).'</pre>';
     //        $cat = new \Furbook\Cat();
     //return 'index'.$v;
     // todos
     $cats = Cat::all();
     return view('cat.index')->with('cats', $cats);
 }
    $cats = Furbook\Cat::all();
    //return $cats;
    return view('cats.index')->with('cats', $cats);
});
Route::get('/cats/breeds/{name}', function ($name) {
    $breed = Furbook\Breed::with('cats')->whereName($name)->first();
    return view('cats.index')->with('breed', $breed)->with('cats', $breed->cats);
});
Route::get('/cats/{cat}', function (\Furbook\Cat $cat) {
    return view('cats.show')->with('cat', $cat);
})->where('cat', '[0-9]+');
Route::get('/cats/create', function () {
    return view('cats.create');
});
Route::post('/cats', function () {
    $cat = \Furbook\Cat::create(Input::all());
    return redirect('/cats/' . $cat->id)->withSuccess('Cat has been created.');
});
Route::get('/cats/{cat}/edit', function (\Furbook\Cat $cat) {
    return view('cats.edit')->with('cat', $cat);
});
Route::put('/cats/{cat}', function (\Furbook\Cat $cat) {
    $cat->update(Input::all());
    return redirect('/cats/' . $cat->id)->withSuccess('Cat has been updated.');
});
Route::get('/cats/{cat}/delete', function (\Furbook\Cat $cat) {
    $cat->delete();
    return redirect('cats')->withSuccess('Cat has been deleted.');
});
Route::get('about', function () {
    return view('about')->with('number_of_cats', 9000);
Ejemplo n.º 4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  Cat  $cat
  * @return Response
  */
 public function destroy(Cat $cat)
 {
     $cat->delete();
     return redirect('cats')->withSuccess('Cat has been deleted.');
 }
Ejemplo n.º 5
0
 /**
  * Remove the specified resource from storage.
  *
  * Метод работает только при указании $id.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $cat = Cat::find($id);
     $cat->delete();
     return redirect('cats')->withSuccess('Cat has been deleted.');
 }