【发布时间】:2017-12-08 07:26:04
【问题描述】:
将我的表单发布到控制器时,laravel 显示此错误:
方法 PTA_OIMS\Http\Controllers\InstructionsController::show() 确实 不存在于 /home/rad/public_html/pta_oims/vendor/laravel/framework/src/Illuminate/Routing/Route.php:333
这是我的 web.php 文件:
Route::post('instructions/view','InstructionsController@view')->name('view');
Route::post('instructions/assign','InstructionsController@assign');
Route::get('instructions/sent','InstructionsController@sent')->name('sent');
Route::post('instructions/reject','InstructionsController@reject')->name('reject');
Route::resource('instructions','InstructionsController');
和刀片视图:
<form action=" {{url('instructions/assign')}}"
变得更加完整:
InstructionsController 并添加了 show()、view() 和 assign() 方法
public function show()
{
return 'show() method done!!';
}
view() 方法
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));
}
查看刀片文件,将数据发送到assign()方法的表单:
<form method="POST" action=" {{url('instructions/assign')}}"
class="form-horizontal" role="form" data-toggle="validator">
{{csrf_field()}}
assign() 方法
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);
}
}
【问题讨论】:
标签: laravel controller routes