【发布时间】:2015-03-07 02:39:25
【问题描述】:
嗨,我已经尝试解决这个问题几个小时了,研究了 Stack Overflow 和许多其他网站,但没有运气。
//-------Route
Route::get('/profile/{firstName}', array(
'as' => 'userProfile',
'uses' => 'ProfileController@user'
));
//--------Controller
class ProfileController extends BaseController {
public function user($firstName) {
$user = User::where('firstName', '=', $firstName);
if($user->count()) {
//First record return from the query
$user = $user->first();
return View::make('profile.user')
->with('user', $user);
}
return "sorry, 404";
//return App::abort(404);
}
}
最后链接:
<li><a href="{{URL::route('userProfile') }}"> My Profile </a></li>
------------------
*如果我手动将用户名放入 URL,它可以工作,但是当我点击链接时,我得到 localhost:8000/profile/{firstName} 并带有“抱歉,404”
谢谢你的帮助!!!
【问题讨论】:
标签: model-view-controller laravel-4 controller routing url-routing