【发布时间】:2014-02-02 01:36:58
【问题描述】:
好的,对 Laravel 4 有点新,我遇到了一个问题。
我在我的路由上使用资源控制器,但我的控制器中还有一些其他功能。正如我所说,我是 Laravel 的新手,所以我什至不确定这是正确的做法。
所以,我的问题是,当我将 edit($id) 函数作为 GET 方法调用,然后将 update($id) 方法作为 POST 时,它工作正常。
Routes.php
Route::get('tasks/edit/{id}', 'TasksController@edit');
Route::post('tasks/edit', 'TasksController@update');
不工作的路线是:
Route::get('tasks/complete/{id}', 'TasksController@complete');
Route::post('tasks/complete', array('as' => 'tasks.completed', 'uses' =>'TasksController@completed')); //I've tried this route a few different ways
在我看来,我正在使用 Form::open() 调用该方法,如下所示:
{{ Form::open(array('route' => array('tasks.completed', $task->id))) }}
在我的 TasksController.php 中,我的方法是:
/**
* Complete the task
*
* @param int $id
* @return Response
*/
public function complete($id) //GET
{
//Find the task by id and allow to complete
return View::make('tasks.complete')->with('task', Task::find($id));
}
/**
* Update the completion
*
* @param int $id
* @return Response
*/
public function completed($id) //POST
{
$tasks = Task::find($id);
$tasks->complete = Task::completion(); //scope query from Model
$tasks->save();
//Redirect to main tasks list
return Redirect::to('/');
}
无论我做什么,我都会收到以下错误:缺少 TasksController::completed() 的参数 1。
我不明白为什么编辑资源可以正常工作,而自定义函数却不行。我几乎可以肯定我忽略了一些东西,但我似乎无法弄清楚是什么。
提前感谢您的帮助!
【问题讨论】:
标签: php laravel laravel-4 laravel-routing