// app/routes.php
Route::get('characters', 'CharactersController@all');
Route::get('characters/{name}', 'CharactersController@detail');
// app/controllers/CharactersController.php
class CharactersController extends BaseController
{
public function all()
{
// show all characters
}
public function detail($name)
{
// find character by name & show detail for example
return View::make('acc.test');
}
}
// app/views/acc/test.blade.php
// HTML::style('css/style.css') loads CSS file located at public/css/style.css
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
{{ HTML::style('css/style.css') }}
</head>
<body>
</body>
</html>
搜索功能
将搜索表单放置在视图文件中的某个位置
<form action="{{ URL::action('CharactersController@search') }}" method="get">
<input type="text" name="search-term">
<input type="submit" value="Search">
</form>
如指定的那样,搜索表单被提交到CharactersController
及其search
方法。
控制器的方法
public function search()
{
$name = Inpute::get('search-term');
$searchResult = Character::where('name', '=', $name)->get();
....
}
注册新路线
Route::get('characters/search', 'CharactersController@search');