Editing product and enabled updating the accounting field
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use App\Http\Requests\ProductAddEdit;
|
||||
use App\Models\{Product,ProductTranslate};
|
||||
|
||||
class ProductController extends Controller
|
||||
@@ -65,37 +66,6 @@ class ProductController extends Controller
|
||||
*/
|
||||
public function details(Request $request,Product $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$validation = $request->validate([
|
||||
'description.name' => 'required|string|min:2|max:255',
|
||||
'active' => 'sometimes|accepted',
|
||||
'model' => 'sometimes|string', // @todo Check that it is a valid model type
|
||||
'model_id' => 'sometimes|int', // @todo Check that it is a valid model type
|
||||
]);
|
||||
|
||||
foreach (collect($validation)->except('description') 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(['description']);
|
||||
$oo = $o->description ?: new ProductTranslate;
|
||||
|
||||
foreach (collect($validation)->get('description',[]) as $key => $item)
|
||||
$oo->{$key} = $item;
|
||||
|
||||
$o->description()->save($oo);
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Product saved');
|
||||
}
|
||||
|
||||
if (! $o->exists && $request->name)
|
||||
$o = Product::where('name',$request->name)->firstOrNew();
|
||||
|
||||
@@ -104,6 +74,31 @@ class ProductController extends Controller
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
public function details_addedit(ProductAddEdit $request,Product $o)
|
||||
{
|
||||
foreach ($request->except(['_token','submit','description']) 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(['description']);
|
||||
$oo = $o->description ?: new ProductTranslate;
|
||||
|
||||
foreach ($request->get('description',[]) as $key => $item)
|
||||
$oo->{$key} = $item;
|
||||
|
||||
$o->description()->save($oo);
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Product saved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage products for a site
|
||||
*
|
||||
|
Reference in New Issue
Block a user