我无法在laravel中传递路由文件中的id
我在路由中声明上述内容以编辑我的数据我无法在laravel中传递路由文件中的id,laravel,Laravel,我在路由中声明上述内容以编辑我的数据 Route::get('editproduct/{id}', 'HomeController@Edit_Product'); 上面是我的editproduct.blade.php页面 <?php $id = $_GET['eid']; $product_info = DB::select("SELECT * FROM `product` WHERE `pid` = '".$id."'"); foreach($product_info as $
Route::get('editproduct/{id}', 'HomeController@Edit_Product');
上面是我的editproduct.blade.php页面
<?php
$id = $_GET['eid'];
$product_info = DB::select("SELECT * FROM `product` WHERE `pid` = '".$id."'");
foreach($product_info as $detail)
{
$actual_image = 'theme/uploads/'.$detail->pimage;
$product_image = $detail->pimage;
$product_name = $detail->pname;
$product_price = $detail->pprice;
}
?>
@include('include/header')
<div class="tab-pane add-product-view" id="profile">
<form name="add_product" method="post" enctype="multipart/form-data" role="form" action="{{ url('edit-product-process') }}">
{{ csrf_field() }}
<div class="form-label">Add Image: </div>
<div class="form-field"><input type="file" name="add_image" id="add_image" value="{{asset($actual_image)}}" /></div>
<img src="{{asset($actual_image)}}" width="50" height="50" />
<div class="form-label">Product Name:</div>
<div class="form-field"><input type="text" name="product_name" id="product_name" value="{{ $product_name }}" /></div>
<div class="form-label">Product Price:</div>
<div class="form-field"><input type="text" name="product_price" id="product_price" value="{{ $product_price }}" /></div>
<div class="btn btn-primary"><input type="submit" name="submit" value="Add Product"</div>
</form>
</div>
@include('include/footer')
我得到下面的错误,请任何人都可以帮助我,我是新的拉雷维尔
page is not found
NotFoundHttpException in RouteCollection.php line 161:
您的路线应为:
Route::get('editproduct/{id}', 'HomeController@Edit_Product')->name('product.edit');
然后您可以将其用作:
{{ route('product.edit', ['id' => $id]) }}
但是在视图中使用DB查询是一种糟糕的做法。
请阅读文档中关于和的更多信息。如果您在尝试提交表单时遇到此错误,您应该检查您的路线。应该是这样的:
Route::post('edit-product-process', 'HomeController@edit_product_process');
此外,要将ID传递到编辑产品\u流程
,您需要在表单中添加ID字段:
<input type="hidden" name="id" value="{{ $id }}">
然后你可以通过
$request->id在编辑产品过程中获得它。检查你的控制器名称,为什么要在其中使用刀片。这是一个糟糕的做法。HomeController.blade.php非常感谢Alexey Mezenin,这是为我写的。
public function Edit_Product($id){
return View::make('editproduct')->with('id', $id);
}
public function edit_product_process(Request $request){
$prd_id = $request->pid;
$imageTempName = $request->file('add_image')->getPathname();
$imageName = $request->file('add_image')->getClientOriginalName();
$path = base_path() . '/theme/uploads/';
$request->file('add_image')->move($path , $imageName);
$remember_token = $request->_token;
$date = date('Y-m-d H:i:s');
$pname = $request->product_name;
$pprice = $request->product_price;
DB::table('product')->where('pid',$prd_id)->update(
array(
'pimage' => $imageName,
'pname' => $pname,
'pprice' => $pprice,
'remember_token' => $remember_token,
'created_at' => $date,
'updated_at' => $date,
)
);
return redirect('dashboard');
}