This is in my store method in the controller:
if (Auth::attempt(Input::only('username', 'password'))) {
$user = Auth::user();
return Redirect::to('user/' . $user->username);
}
The show method:
public function show(User $user)
{
return View::make('user.profile', ['user' => $user]);
}
and the view to it:
<h1>Profile page of {{ $user->username }}</h1>
{{ Form::open(['route' => 'user.destroy']) }}
<div class="form-group">
{{ Form::submit('Logout', ['class' => 'btn btn-primary']) }}
{{ link_to('user/'.$user->username.'/edit', 'Edit', ['class' => 'btn btn-default']) }}
</div>
{{ Form::close() }}
which should lead to the destroy action (but it doesn't because of the wrong POST action URL, that you can see a bit further down):
public function destroy(User $user)
{
Auth::logout();
return Redirect::route('user.index');
}
and, as you might have thought already, I am using Route resources + model minding. This is my routes.php file:
Route::bind('user', function ($username) {
return User::where('username', $username)->first();
});
Route::resource('user', "UsersController");
So, when I log-in the user, I am redirected to .../user/relevant_usrename, which is fine, but when I inspect the Form, it looks like this:
<form method="POST" action="http://localhost:8000/user/%7Buser%7D" accept-charset="UTF-8">
...
</form>
You see that the POST action is wrong, although I seem to be passing correctly the object. How can I fix this? And please give me some explanation around the problem, instead of just a code solution, because I would like to understand what have I mistaken.