laravel - 带参数的 Controller 路由

标签 laravel laravel-4

Laravel 4 遇到了一些 n00b 问题。我有以下路线:

Route::get('search', 'MovieController@search');
Route::get('edit/{$id}', 'MovieController@edit');
Route::get('/', 'MovieController@index');

和以下 Controller :

class MovieController extends BaseController {

protected $layout = 'layouts.master';

public function index()
{
    $movies = Movie::paginate(30);
    return View::make('index')->with('movies', $movies);
}

public function search()
{
    if(isset($_REQUEST['sq'])) {
        Cache::forever('sq', $_REQUEST['sq']);
    }
    $movies = Movie::where('title', 'LIKE', '%'.Cache::get('sq').'%')->paginate(30);

    return View::make('index')->with('movies', $movies);
}

public function edit($id) {
    return View::make('edit')->with('id', $id);
    }

}

现在这样的调用不起作用:

<a href="edit/{{ $movie->movie_id }}">

我收到“NotFoundHttpException”。 URL 似乎是正确的:laravel/public/edit/2 例如

如果我从代码中删除所有 $id 内容,那么我只路由到编辑,它就可以工作。

希望我能充分表达自己,以便有人可以帮助我。这让我发疯。

问候

最佳答案

在你的routes.php中,它不是Route::get('edit/{$id} ...但是Route::get('edit/{id}

关于laravel - 带参数的 Controller 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16934661/

相关文章:

javascript - Vue.js:在 laravel 公共(public)文件夹中显示个人资料图片

php - 连接表错误未定义属性

php - Laravel 如何知道调度程序何时更新?

php - Laravel redirect::route 在页面加载之间显示一条消息

php - 查询 Laravel 查询生成器

php - 如何在 Laravel 中对指定的 Controller 操作进行过滤

php - 如何在 Eloquent Orm 中实现自引用(parent_id)模型

php - Laravel Eloquent 多列 IN 子句

php - Laravel 4 迁移 : class not found exception

php - 验证字段输入是字符串 laravel