/**
  * Select a specific beer based on its ID
  *
  * @param $id
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 public function beer($id)
 {
     $beer = Beer::find($id);
     if (!!$beer) {
         $beer->load('brewery', 'style');
         return response(['status' => 'ok', 'message' => 'The beer with the id of ' . $id, 'beer' => $beer]);
     }
     return response(['status' => 'failed', 'error' => 'The beer with the id ' . $id . ' does not exist'], 400);
 }
Beispiel #2
0
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
use App\User;
use App\Beer;
Route::get('/', function () {
    return view('welcome');
});
Route::get('/api/v1/beers', function () {
    header("Access-Control-Allow-Origin: *");
    return Beer::with('categories.ratings')->get();
});
Route::get('/api/v1/crisp', function () {
});
Route::get('/api/v1/search/{parameter}', function ($parameter) {
    header("Access-Control-Allow-Origin: *");
    if (!$parameter) {
        return [];
    }
    return Beer::where('name', 'LIKE', '%' . $parameter . '%')->get();
});
Route::get('/api/v1/beer/{id}', function ($id) {
    return Beer::find($id)->with('categories')->first();
});
Route::resource('api/v1/beer', 'BeerController');
Route::any('{all}', function ($uri) {
    return ['status' => 'Not Found'];
})->where('all', '.*');
Beispiel #3
0
 public function getDelete($id)
 {
     $beer = \App\Beer::find($id);
     $recipe = \App\Recipe::where('beer_id', $id)->get();
     foreach ($recipe as $item) {
         $item->delete();
     }
     $beer->delete();
     \Session::flash('flash_message', $beer->name . ' was deleted.');
     return redirect('/beer');
 }