Sunday, 15 May 2011

php - Laravel 4 link_to with user id generates NotFoundHttpException -



php - Laravel 4 link_to with user id generates NotFoundHttpException -

userscontroller:

protected $user; public function __construct(user $user) { $this->user = $user; } public function show($id) { $user = $this->user->find($id); homecoming view::make('users.show')->with('user',$user); }

model:

protected $table = 'users';

route:

route::resource('users','userscontroller');

code creates link in views/users: "index.blade.php":

{{ link_to("/users/show/{$user->id}", ($user->first_name), $secure = null) }}

object code in page beingness linked to, in views/users: "show.blade.php":

$user->{field} ...

where code puts in field names, not enclosed in {} of course.

the link generates url:

https://.../users/show/{#}

where {#} user id associated link, e.g. .../users/show/7

clicking link in users/index generates notfoundhttpexception.

i know basic stuff, going crazy trying figure out i'm doing wrong. i'm not sure understand "$secure = null" for, i'm next laravel docs; makes no difference if it's there or not, still getting not found exception if remove it. doing wrong?

thanks much!

you created resource controller , maps to:

verb path action route name /resource/{resource} show resource.show

you can create link named route:

{{link_to_route('users.show', $user->first_name, $user->id)}}

or

{{link_to('users/'.$user->id, $user->first_name)}}

php url laravel

No comments:

Post a Comment