Optimising Supplier Layout and source code placement
This commit is contained in:
@@ -176,71 +176,6 @@ class AdminController extends Controller
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Site up site wide suppliers, or a site's supplier details
|
||||
*
|
||||
* @note This method is protected by the routes
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function supplier()
|
||||
{
|
||||
return view('a.supplier.home');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a suppliers details
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Supplier $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function supplier_addedit(Request $request,Supplier $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$validation = $request->validate([
|
||||
'name' => 'required|string|min:2|max:255',
|
||||
'active' => 'sometimes|accepted',
|
||||
'address1' => 'nullable|string|min:2|max:255',
|
||||
'address2' => 'nullable|string|min:2|max:255',
|
||||
'city' => 'nullable|string|min:2|max:64',
|
||||
'state' => 'nullable|string|min:2|max:32',
|
||||
'postcode' => 'nullable|string|min:2|max:8',
|
||||
'supplier_details.notes' => 'nullable|string|min:3',
|
||||
'supplier_details.accounts' => 'nullable|email',
|
||||
'supplier_details.support' => 'nullable|email',
|
||||
'supplier_details.payments' => 'nullable|string|min:3',
|
||||
]);
|
||||
|
||||
foreach (collect($validation)->except('supplier_details') as $key => $item)
|
||||
$o->{$key} = $item;
|
||||
|
||||
$o->active = (bool)$request->active;
|
||||
|
||||
try {
|
||||
$o->save();
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->back()->withErrors($e->getMessage())->withInput();
|
||||
}
|
||||
|
||||
$o->load(['detail']);
|
||||
$oo = $o->detail ?: new SupplierDetail;
|
||||
|
||||
foreach (collect($validation)->get('supplier_details',[]) as $key => $item)
|
||||
$oo->{$key} = $item;
|
||||
|
||||
$o->detail()->save($oo);
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Supplier saved');
|
||||
}
|
||||
|
||||
if (! $o->exists && $request->name)
|
||||
$o = Supplier::where('name',$request->name)->with(['details'])->firstOrNew();
|
||||
|
||||
return view('a.supplier.details')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Site setup
|
||||
*
|
||||
|
Reference in New Issue
Block a user