2017-07-04 46 views
1

當我郵寄的形式向控制器的laravel顯示了這個錯誤:Laravel 5.3:方法[演出]不存在

Method PTA_OIMS\Http\Controllers\InstructionsController::show() does not exist in /home/rad/public_html/pta_oims/vendor/laravel/framework/src/Illuminate/Routing/Route.php:333

這是我的web.php文件:

Route::post('instructions/view','[email protected]')->name('view'); 
Route::post('instructions/assign','[email protected]'); 
Route::get('instructions/sent','[email protected]')->name('sent'); 
Route::post('instructions/reject','[email protected]')->name('reject'); 
Route::resource('instructions','InstructionsController'); 

和刀片觀點:

<form action=" {{url('instructions/assign')}}" 

成了更完整:

InstructionsController並加入顯示(),視圖()和分配()方法

public function show() 
{ 
    return 'show() method done!!'; 
} 

視圖()方法

public function view(Request $request) 
{ 
    $boxes = $this->getBoxesList(); 
    $id = $request->input('id'); 
    $data = Kartable::where('id', '=', $id) 
     ->with('instruction') 
     ->first(); 
    if ($data->view_date == NULL) { 
     $this->insertViewDate($id); 
    } 

    return view('instructions.view', array('data' => $data, 'boxes' => $boxes)); 
} 

視圖葉片文件,發送所述數據到分配的形式()方法:

<form method="POST" action=" {{url('instructions/assign')}}" 
    class="form-horizontal" role="form" data-toggle="validator"> 

    {{csrf_field()}} 

分配()方法

public function assign(Request $input) 
{ 
    try { 

     $inst_id = $input->input('inst_id'); 
//  $childsInsts = Instructions::where('parent_id', '=', $inst_id) 
//    ->where('status', '=', 0) 
//    ->get(); 
     $formData = $input->all(); 
     $step = 0; 
     foreach ($formData['box'] as $box) { 
      foreach ($box as $id_reciver) 
       DB::transaction(function() use ($formData, $inst_id, $id_reciver, $step) { 
        $kar = new Kartable(); 

        $kartable_id = $formData['kartable_id']; 
        $current_box = $formData['current_box']; 
        $kar->inst_id = $inst_id; 
        $kar->parent_id = $kartable_id; 
        $kar->id_sender = $current_box; 
        $kar->id_reciver = $id_reciver; 
        $kar->status = 1; 
        $kar->save(); // insert for new record of kartable 
        $step += 1; 
        if ($step < 2) { 
         $kartable = new Kartable(); 
         $kartable 
          ->where('id', '=', $kartable_id) 
          ->update(['status' => 3]); //change status of old row kartable 
        } 
       }); 

      return redirect()->route('instructions.index'); 
     } 
    } catch (\Exception $e) { 
     dd($e); 
    } 
} 

回答

-1

你有沒有檢查過你的「InstructionsController」有一個「顯示」方法?因爲你聲明瞭Route :: resource('instructions','InstructionsController'); 然後你Laravel假定控制器具有以下方法:

enter image description here

檢查this docs from Laravel bro.

希望幫助你。

0

我猜想這是因爲你沒有在你的<form>標籤method=這將導致形式與GET要求提交,看到你有一Route::resource設立它會假設你想訪問show方法。

改變你的表單標籤是:

<form method="POST" action="{{ url('instructions/assign') }}"> 

而且,不要忘了補充:

{{ csrf_field() }} 

表單裏面,這樣你就不會得到TokenMismatchException

希望這會有所幫助!

+0

問題已更新 –