2016-07-03 6 views
0

破壊方法のルートがあれば教えてください。私はテーブル内のレコードを削除しようとしていますが、削除ボタンを押すと、私のルートが定義されていないと言われているので、私の削除アクションは機能しません。破壊方法のルートはありますか?

Route [result.destroyEmployee]が定義されていません。 (閲覧:C:\ Users \ユーザーJohnFrancis \ LaravelFrancis \リソース\ビュー\アカウント\のsearch.blade.php)

ルート

//READ 
Route::get('/search', 
[ 
    'uses' => '\App\Http\Controllers\[email protected]', 
    'as' => 'account.search', 
]); 


//EDIT 
Route::get('/edit/{id}', 
[ 
    'uses' => '\App\Http\Controllers\[email protected]', 
    'as' => 'account.edit', 
]); 

それが識別されますので、私は編集のルートでidを通過しました誰が現在行動しているのか。

コントローラー:

//READ 
public function getEmployee() 
{ 
    $result = DB::table('users')->get(); 

    return view ('account.search')->with('result', $result); 
} 


//EDIT 
public function editEmployee($id) 
{ 
    $result = User::find($id); 

             //key  //value 
    return view ('account.edit')->with('result', $result); 
} 

//DELETE 
public function destroyEmployee($id) 
{ 
    $result = User::destroy($id); 

    return redirect()->route('account.search'); 
} 

search.blade.php

@foreach ($result as $row) 
    <tr class = "success"> 
     <td>{{ $row->id }}</td> 
     <td>{{ $row->first_name }}</td> 
     <td>{{ $row->last_name }}</td> 
     <td>{{ $row->middle_name }}</td> 
     <td>{{ $row->email }}</td> 
     <td>{{ $row->username }}</td> 
     <td> 
      <a href = "{{ route ('account.edit', $row->id) }}"><button type = "submit" class = "btn btn-warning">Edit</button></a> 

      <a href = "{{ route ('result.destroyEmployee', $row->id) }}"><button type = "submit" class = "btn btn-danger">Delete</button></a> 
     </td> 
    </tr> 
@endforeach 

edit.blade.php

<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.edit', $result->id) }}"> 

<div class = "form-group"> 

    <label for = "email" class = "control-label">Email Address</label> 
    <input type = "text" name = "email" class = "form-control" value = "{{ $result->email }}"> 

</div> 

<div class = "form-group"> 

    <label for = "username" class = "control-label">Username</label> 
    <input type = "text" name = "username" class = "form-control" value = "{{ $result->username }}"> 

</div> 

<div class = "form-group"> 

    <button type = "submit" class = "btn btn-success">Save</button> 

</div> 

<input type = "hidden" name = "id" value = "{{ $result->id }}"> 
<input type = "hidden" name = "_token" value = "{{ Session::token() }}"> 

</form> 
+0

まあをクリックの上、それをヒットしようとしている、私はdestroyEmployee'方法 'を指す任意の経路が表示されません。それがエラーの内容です。 –

+0

@VishalShこのためのルートを作成する必要はありますか? – Francisunoxx

答えて

0

あなたroutes.phpにこのルートを追加します。私はGET要求での削除操作を推奨しませんが、アンカータグで定義された操作があるので、GET要求になります。

//DELETE 
Route::get('/destroy/{id}', 
[ 
    'uses' => '[email protected]', 
    'as' => 'result.destroyEmployee', 
]); 

あなたはこのルートが定義されていない、あなたはArchiveボタン

+0

なぜあなたはGETメソッドで奨励しないのですか?あなたはPOSTメソッドのいくつかの例を提供できますか? – Francisunoxx

+0

アクションによってデータベースにDELETEが発生し、この操作の理想的なREST呼び出しはDELETE要求です。アンカータグをボタンタグに変更し、 'onclick'メソッドを追加して、GET以外のリクエストに対してAJAX呼び出しを送信する必要があります。 (あなたはいつでもフォームを使うことができます) –

+0

タグ内で操作が割り当てられていない場合。アクションはボタンの中にあるので、これはPOSTリクエストになりますが、データベースの権利でも削除されますか?私が間違っているなら私を訂正してください。 – Francisunoxx