/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $receipt_id = $request->segment(4); if (!Receipt::find($receipt_id)) { abort(404); } return $next($request); }
/** * Remove the specified resource from storage. * * @param $receipt_id * @param $category_id * @return Response * @internal param int $id */ public function destroy($receipt_id, $category_id) { $receipt = Receipt::find($receipt_id); $category = Category::find($category_id); if ($receipt->hasCategory($category)) { $receipt->categories()->detach($category->id); } return 'success'; }
/** * Receipt DELETE test * * @return void */ public function testDELETEReceipt() { $receipt = Receipt::first(); $endpoint = $this->getEndpointWithToken($this->endpoint . '/' . $receipt->id); $this->call('DELETE', $endpoint); //fetch inserted receipt $deleted_receipt = Receipt::find($receipt->id); $this->assertNull($deleted_receipt); }
/** * Remove category from receipt test * */ public function testRemoveCategoryReceipt() { $receipt = Factory::create('App\\Receipt'); $category = Factory::create('App\\Category'); $receipt->categories()->attach($category->id); $this->assertTrue($receipt->hasCategory($category)); $fullEndpoint = $this->getFullEndpoint($receipt, $category); $endpoint = $this->getEndpointWithToken($fullEndpoint); $this->call('DELETE', $endpoint); //fetch receipt again and check categories $receipt = \App\Receipt::find($receipt->id); $this->assertFalse($receipt->hasCategory($category)); }