|
|
@ -5,13 +5,14 @@ namespace App\Http\Controllers\Partners; |
|
|
use Illuminate\Http\Request; |
|
|
use Illuminate\Http\Request; |
|
|
use App\Entities\Partners\Customer; |
|
|
use App\Entities\Partners\Customer; |
|
|
use App\Http\Controllers\Controller; |
|
|
use App\Http\Controllers\Controller; |
|
|
|
|
|
use App\Http\Requests\Partners\CustomerCreateRequest; |
|
|
|
|
|
|
|
|
class CustomersController extends Controller |
|
|
class CustomersController extends Controller |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
|
* Display a listing of the customer. |
|
|
* Display a listing of the customer. |
|
|
* |
|
|
* |
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
|
|
* @return \Illuminate\View\View |
|
|
*/ |
|
|
*/ |
|
|
public function index() |
|
|
public function index() |
|
|
{ |
|
|
{ |
|
|
@ -28,7 +29,7 @@ class CustomersController extends Controller |
|
|
/** |
|
|
/** |
|
|
* Show the create customer form. |
|
|
* Show the create customer form. |
|
|
* |
|
|
* |
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
|
|
* @return \Illuminate\View\View |
|
|
*/ |
|
|
*/ |
|
|
public function create() |
|
|
public function create() |
|
|
{ |
|
|
{ |
|
|
@ -38,25 +39,13 @@ class CustomersController extends Controller |
|
|
/** |
|
|
/** |
|
|
* Store a newly created customer in storage. |
|
|
* Store a newly created customer in storage. |
|
|
* |
|
|
* |
|
|
* @param \Illuminate\Http\Request $request |
|
|
|
|
|
* |
|
|
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
|
|
* @param \App\Http\Requests\Partners\CustomerCreateRequest $customerCreateForm |
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
|
*/ |
|
|
*/ |
|
|
public function store(Request $request) |
|
|
|
|
|
|
|
|
public function store(CustomerCreateRequest $customerCreateForm) |
|
|
{ |
|
|
{ |
|
|
$newCustomerData = $this->validate($request, [ |
|
|
|
|
|
'name' => 'required|max:60', |
|
|
|
|
|
'email' => 'nullable|email|unique:customers,email', |
|
|
|
|
|
'phone' => 'nullable|max:255', |
|
|
|
|
|
'pic' => 'nullable|max:255', |
|
|
|
|
|
'address' => 'nullable|max:255', |
|
|
|
|
|
'website' => 'nullable|url|max:255', |
|
|
|
|
|
'notes' => 'nullable|max:255', |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
Customer::create($newCustomerData); |
|
|
|
|
|
|
|
|
|
|
|
flash(trans('customer.created'), 'success'); |
|
|
|
|
|
|
|
|
Customer::create($customerCreateForm->validated()); |
|
|
|
|
|
flash(__('customer.created'), 'success'); |
|
|
|
|
|
|
|
|
return redirect()->route('customers.index'); |
|
|
return redirect()->route('customers.index'); |
|
|
} |
|
|
} |
|
|
@ -65,8 +54,7 @@ class CustomersController extends Controller |
|
|
* Show the specified customer. |
|
|
* Show the specified customer. |
|
|
* |
|
|
* |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* |
|
|
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
|
|
* @return \Illuminate\View\View |
|
|
*/ |
|
|
*/ |
|
|
public function show(Customer $customer) |
|
|
public function show(Customer $customer) |
|
|
{ |
|
|
{ |
|
|
@ -77,8 +65,7 @@ class CustomersController extends Controller |
|
|
* Show the edit customer form. |
|
|
* Show the edit customer form. |
|
|
* |
|
|
* |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* |
|
|
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
|
|
* @return \Illuminate\View\View |
|
|
*/ |
|
|
*/ |
|
|
public function edit(Customer $customer) |
|
|
public function edit(Customer $customer) |
|
|
{ |
|
|
{ |
|
|
@ -90,8 +77,7 @@ class CustomersController extends Controller |
|
|
* |
|
|
* |
|
|
* @param \Illuminate\Http\Request $request |
|
|
* @param \Illuminate\Http\Request $request |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* |
|
|
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
|
*/ |
|
|
*/ |
|
|
public function update(Request $request, Customer $customer) |
|
|
public function update(Request $request, Customer $customer) |
|
|
{ |
|
|
{ |
|
|
@ -108,7 +94,7 @@ class CustomersController extends Controller |
|
|
|
|
|
|
|
|
$customer->update($customerData); |
|
|
$customer->update($customerData); |
|
|
|
|
|
|
|
|
flash(trans('customer.updated'), 'success'); |
|
|
|
|
|
|
|
|
flash(__('customer.updated'), 'success'); |
|
|
|
|
|
|
|
|
return redirect()->route('customers.show', $customer->id); |
|
|
return redirect()->route('customers.show', $customer->id); |
|
|
} |
|
|
} |
|
|
@ -117,25 +103,24 @@ class CustomersController extends Controller |
|
|
* Remove the specified customer from storage. |
|
|
* Remove the specified customer from storage. |
|
|
* |
|
|
* |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* @param \App\Entities\Partners\Customer $customer |
|
|
* |
|
|
|
|
|
* @return \Illuminate\Http\Response |
|
|
|
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
|
*/ |
|
|
*/ |
|
|
public function destroy(Customer $customer) |
|
|
public function destroy(Customer $customer) |
|
|
{ |
|
|
{ |
|
|
// TODO: user cannot delete customer that has been used in other table
|
|
|
// TODO: user cannot delete customer that has been used in other table
|
|
|
$this->validate(request(), [ |
|
|
|
|
|
|
|
|
request()->validate([ |
|
|
'customer_id' => 'required', |
|
|
'customer_id' => 'required', |
|
|
]); |
|
|
]); |
|
|
|
|
|
|
|
|
$routeParam = request()->only('page', 'q'); |
|
|
$routeParam = request()->only('page', 'q'); |
|
|
|
|
|
|
|
|
if (request('customer_id') == $customer->id && $customer->delete()) { |
|
|
if (request('customer_id') == $customer->id && $customer->delete()) { |
|
|
flash(trans('customer.deleted'), 'warning'); |
|
|
|
|
|
|
|
|
flash(__('customer.deleted'), 'warning'); |
|
|
|
|
|
|
|
|
return redirect()->route('customers.index', $routeParam); |
|
|
return redirect()->route('customers.index', $routeParam); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
flash(trans('customer.undeleted'), 'danger'); |
|
|
|
|
|
|
|
|
flash(__('customer.undeleted'), 'danger'); |
|
|
|
|
|
|
|
|
return back(); |
|
|
return back(); |
|
|
} |
|
|
} |
|
|
|