所以我无法弄清楚为什么这不会将变量传递给我的控制器。
继承我的/Controllers/FriendController.php getAccept功能:
public function getAccept($username)
{
$user = User::where('username', $username)->first();
if (!$user) {
return redirect()->route('home')->with('info', 'That user could not be found!');
}
if (!Auth::user()->hasFriendRequestRecieved($user)) {
return redirect()->route('home');
}
Auth::user()->acceptFriendRequest($user);
return redirect()->route('profile.index', ['username' => $user->username])->with('info', 'Friend request acccepted.');
}
}
继承我的刀片,接受朋友请求按钮的位置是:
@extends('templates.default')
@section('content')
<div class="row">
<div class="col-lg-5">
@include('user.partials.userblock')
<hr>
</div>
<div class="col-lg-4 col-lg-offset-3">
@if (Auth::user()->hasFriendRequestPending($user))
<p>Waiting for {{ $user->getNameOrUsername() }} to accept your request.</p>
@elseif (Auth::user()->hasFriendRequestRecieved($user))
<a href="{{ route('friends.accept', ['username' => $user->username]) }}" class="btn btn-primary">Accept friend request</a>
@elseif (Auth::user()->isFriendWith($user))
<p>You and {{ $user->getNameOrUsername() }} are friends.</p>
@else
<a href="{{ route('friends.add', ['username' => $user->username]) }}" class="btn btn-primary">Add as friend</a>
@endif
<h4>{{ $user->getFirstNameOrUsername() }}'s friends.</h4>
@if (!$user->friends()->count())
<p>{{ $user->getFirstNameOrUsername() }} has no friends.</p>
@else
@foreach ($user->friends() as $user)
@include('user/partials/userblock')
@endforeach
@endif
</div>
</div>
@stop
答案 0 :(得分:0)
好的我自己解决了这个问题,在路由中遗漏了一个变量,所以现在我的路由看起来像这样:
Route::get('friends/accept/{username}', [
'uses' => '\Aries\Http\Controllers\FriendController@getAccept',
'as' => 'friends.accept',
'middleware' => ['auth'],
]);
忘了:
{username}