Add function to fetch a single customer
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use App\Models\Customer;
|
||||
use App\Support\ApiDataTransformer;
|
||||
use Pest\ArchPresets\Custom;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
@@ -21,6 +22,20 @@ public function index()
|
||||
});
|
||||
}
|
||||
|
||||
public function single($id)
|
||||
{
|
||||
$customer = Customer::with(['contacts' => function ($query) {
|
||||
$query->orderBy('is_primary', 'desc');
|
||||
}, 'paymentTerms'])->findOrFail($id);
|
||||
|
||||
$customerArray = $customer->toArray();
|
||||
if ($customer->paymentTerms) {
|
||||
$customerArray['payment_terms'] = $customer->paymentTerms->toArray();
|
||||
unset($customerArray['payment_terms_id']);
|
||||
}
|
||||
return ApiDataTransformer::snakeToCamel($customerArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random available customer number
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user