从我之前的问题中,我从用户那里得到了这个代码。
// 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">
public function search()
{
$name = Input::get('search-term');
$searchResult = Character::where('name', '=', $name)->get();
....
}
Route::get('characters/search', 'CharactersController@search');
我怎么能在:
public function detail($name) { // find character by name & show detail for example return View::make('acc.test'); }
我怎么能按名字找到角色?我试过做类似的事情
$name = $player->name
(我有一个名为 player 的模型,我也将 Character::where 更改为 Player::where),我必须在其中插入什么?另外,我怎么能在视图中显示它?
所以我的意思是,当我按名称搜索玩家时,它会显示每个特定玩家的玩家名称($player->name)。
我还必须将模型中的关系更改为 HasMany 或类似的东西吗?