Payments.php
1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace App\Http\Controllers\Api\Expenses;
use App\Http\Controllers\ApiController;
use App\Http\Requests\Expense\Payment as Request;
use App\Models\Expense\Payment;
use App\Transformers\Expense\Payment as Transformer;
use Dingo\Api\Routing\Helpers;
class Payments extends ApiController
{
use Helpers;
/**
* Display a listing of the resource.
*
* @return \Dingo\Api\Http\Response
*/
public function index()
{
$payments = Payment::with(['account', 'vendor', 'category'])->collect();
return $this->response->paginator($payments, new Transformer());
}
/**
* Display the specified resource.
*
* @param Payment $payment
* @return \Dingo\Api\Http\Response
*/
public function show(Payment $payment)
{
return $this->response->item($payment, new Transformer());
}
/**
* Store a newly created resource in storage.
*
* @param $request
* @return \Dingo\Api\Http\Response
*/
public function store(Request $request)
{
$payment = Payment::create($request->all());
return $this->response->created(url('api/payments/'.$payment->id));
}
/**
* Update the specified resource in storage.
*
* @param $payment
* @param $request
* @return \Dingo\Api\Http\Response
*/
public function update(Payment $payment, Request $request)
{
$payment->update($request->all());
return $this->response->item($payment->fresh(), new Transformer());
}
/**
* Remove the specified resource from storage.
*
* @param Payment $payment
* @return \Dingo\Api\Http\Response
*/
public function destroy(Payment $payment)
{
$payment->delete();
return $this->response->noContent();
}
}