0
동적 변형으로 제품을 업데이트하려고 할 때 추가 또는 삭제에는 문제가 없지만 업데이트하려고 할 때마다 마지막 레코드로 업데이트됩니다 모든 분야에서. 내가제품 변형 데이터를 업데이트 할 때마다 laravel에서 마지막 레코드로 업데이트 5.3
- 컬러 삽입 한 동적 변형 업데이트하려고
- 빨강,
- 모양 -square
의에 대한 동적 양식 필드를 제대로 작업을 삽입하지만, 내가 그것을 업데이 트하려고하면 필드와 나는 필드의 구별 할 수 없을 것입니다 둘 다 필드와 블레이드 파일의 형태로 반환하기 때문에 두 번째 값으로 업데이트 된 첫 번째 값은 rray.
내가 값의 반복 분야 모두에서 마지막 값으로 업데이트하려고 할 때 그래서 출력은
- 모양 평방
- 모양 평방
컨트롤러 모양을 기능 :
public function updateProducts($id, Request $request) {
$featured = Input::has('featured') ? true : false;
// Find the Products ID from URL in route
$product = Product::findOrFail($id);
// Update product
$product->update(array(
'product_name' => $request->input('product_name'),
'product_qty' => $request->input('product_qty'),
'product_sku' => $request->input('product_sku'),
'price' => $request->input('price'),
'reduced_price' => $request->input('reduced_price'),
'cat_id' => $request->input('cat_id'),
'brand_id' => $request->input('brand_id'),
'featured' => $featured,
'description' => $request->input('description'),
'product_spec' => $request->input('product_spec'),
));
$product->update($request->all());
$variants = VariantsOption::where('products_id', $id)->get();
$test=$request->all();
foreach ($variants as $v) {
$x =$v->id;
//dd($x);
//$variants_id = $request->input('variants_id');
//dd($variants_id); ans in array
//exit;
//dd($v
// $variants->products_id = $insertedid;
foreach($test['variants_id'] as $key=>$attrib){
$var_name=$test['txt'][$key];
$varid=$attrib;
//dd($varid);
$variants = new VariantsOption;
//$variants->products_id=$insertedid;
$data=array(
//'variants_id' => $request->input('variants_id'),
'variants_id'=>$varid,
'variants_name'=>$var_name
);
$variants->where('id', '=' , $x)->update($data);
}
}
return redirect('/admin/products/');
}
0 함수
// Will return a ModelNotFoundException if no user with that id
try
{
$product = Product::findOrFail($id);
}
// catch(Exception $e) catch any exception
catch(ModelNotFoundException $e)
{
dd(get_class_methods($e)) // lists all available methods for exception object
dd($e)
}
그것은 그 $id
와 제품처럼 보이는 내에서 클래스
use Illuminate\Database\Eloquent\ModelNotFoundException;
또는 예외 처리기를 추가로 다음
데이터베이스를 업데이트하는 동안 조건을 포함해야합니다. – Sona
친구가 없습니다. 정보가 업데이트되는 동안 조건이 필요합니다. 화를 내기 전에 쿼리를 인쇄 할 수 있습니다. 일반적으로 id는 $ id를 의미하지 않습니다. 그래서 그것이 일어날 수 있습니다. 그래서 당신이 먼저 쿼리를 출력하도록 요청하십시오. –
$ 변형에 대한 출력을 가져 와서 whats 출력을 확인 하시겠습니까? –