Paragonik/paragonik-backend/app/Http/Controllers/ReceiptController.php

80 lines
2.1 KiB
PHP
Raw Permalink Normal View History

2019-12-08 22:02:03 +01:00
<?php
namespace App\Http\Controllers;
use App\Models\Receipt;
use Illuminate\Http\Request;
class ReceiptController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return response()->json(Receipt::with('receipt_items')->get(), 200);
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$receipt = Receipt::create([
'payment_date' => $request->payment_date,
'payment_amount' => $request->payment_amount,
'user_id' => $request->user_id,
'store_id' => $request->store_id,
]);
return response()->json($receipt, 201);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$receipt = Receipt::with('receipt_items')->get()->find($id);
if(is_null($receipt)){ return response()->json(["message " => "Record not found."], 404);}
return response()->json($receipt, 200);
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$receipt = Receipt::find($id);
if(is_null($receipt)){ return response()->json(["message " => "Record not found."], 404);}
$receipt->update($request->all());
return response()->json($receipt, 200);
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$receipt = Receipt::find($id);
if(is_null($receipt)){ return response()->json(["message " => "Record not found."], 404);}
$receipt->delete();
return response()->json(null, 204);
}
}