2016-12-17 3 views
1

私のデータを編集するルート上に上記のことを宣言しています。上記Iルートファイルのidをlaravelに渡すことができません

Route::get('editproduct/{id}', '[email protected]_Product'); 

私editproduct.blade.phpページには、これは私が以下のエラーを取得しています私の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'); 
    } 

ある

<?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') 

で、誰でもできるようにすることができますしてください私を助けるために、私はlaravelで新しいです。

page is not found 
NotFoundHttpException in RouteCollection.php line 161: 

答えて

1

フォームを送信しようとしているときにこのエラーが発生する場合は、経路を確認する必要があります。それは次のようになります。

<input type="hidden" name="id" value="{{ $id }}"> 

そしてあなたは$request->id

edit_product_processにそれを得ることができます。

また
Route::post('edit-product-process', 'HomeControl[email protected]_product_process'); 

、フォームにIDとフィールドを追加する必要がedit_product_processにIDを渡します

+1

Alexey Mezeninさん、ありがとうございますm e。 –

0

あなたのルートはようでなければなりません:次に、あなたのようにそれを使用することができます

Route::get('editproduct/{id}', '[email protected]_Product')->name('product.edit'); 

{{ route('product.edit', ['id' => $id]) }} 

しかし、それはビューでDBクエリを使用するにはひどい練習です。

queriescontrollersについては、こちらのドキュメントをご覧ください。

0

コントローラの名前を確認する理由は何ですか?これは悪い習慣です.HomeController.blade.php

関連する問題