I have been using a composer package laravel-acquaintances and have connected it up to my profile. I have also managed to befriend users, my issue is once I try to get all friendships it doesn't allow me to show it based off each users, username or even ID.
I will present the code I presume is important below, please let me know if I have missed anything out.
web.php
Route::get('/followers/{$user->}', 'AcquaintancesController@index')->name('acquaintances.index');
AcquaintancesController.php
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AcquaintancesController extends Controller
{
public function index(User $user)
{
$user = Auth::user();
$friends = $user->getAllFriendships();
return view('acquaintances.index',[
'friends' => $friends
]);
}
}
acquaintances/index.blade.php
<div class="tab-pane fade" id="acquaintances">
<div class="row pt-5">
<ul>{{$friends}}</ul>
</div>
</div>
view on site
I have tried to use a foreach;
- {{$friends->user->username}}
... however that didn't work
I also tried a few other options that I assume were not the best. Please I would appreciate the help.
My Answer:
id}', 'UserController@getFollowers');
__UserController.php__
php
use Acquaintances;
public function getFollowers($userId) {
$user = User::find($userId);
$followers = Acquaintances::getFollowers($user);
return view('followers', compact('followers'));
}
In the above code, we are trying to get the followers of a user based on their user ID. Make sure you have imported the necessary classes and models in your UserController.php file.
Also, make sure you have a view file named 'followers.blade.php' in your views folder to display the followers.
If you are still facing issues, please provide more details or code snippets for further assistance.
Rate this post
4 of 5 based on 7142 votesComments