我在编辑数据的路径中声明了上述内容。
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')
这是我的HomeController.blade.php
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');
}
我收到以下错误,请任何人都可以帮助我,我是laravel的新人。
page is not found
NotFoundHttpException in RouteCollection.php line 161:
答案 0 :(得分:1)
如果您在尝试提交表单时收到此错误,则应检查路线。它应该是这样的:
Route::post('edit-product-process', 'HomeController@edit_product_process');
另外,要将ID传递到edit_product_process
,您需要在表单中添加带ID的字段:
<input type="hidden" name="id" value="{{ $id }}">
然后您可以使用edit_product_process
$request->id
中获取它
答案 1 :(得分:0)
您的路线应为:
Route::get('editproduct/{id}', 'HomeController@Edit_Product')->name('product.edit');
然后您可以将其用作:
{{ route('product.edit', ['id' => $id]) }}
但在视图中使用数据库查询是一种可怕的做法。
请在文档中详细了解queries和controllers。
答案 2 :(得分:0)
检查你的控制器名称为什么在那里使用刀片。这是不好的做法.HomeController.blade.php