V
V
Vladislav2017-04-05 16:02:51
Laravel
Vladislav, 2017-04-05 16:02:51

How can I display a list of users with links and follow them?

How can I display a list of users with links and follow them?
Controller (part of the code to navigate to the user)
public function show()
{
$user = User::all();
return view('auth.pre', array('us'=>$user));
}
Now displays the page of the user under which I sit.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sungat Arynov, 2017-04-06
@Ginkidayo

Example for displaying one user :

public function show($id)
{

$user = User::whereId($id)->firstOrFail(); 

return view('user.show', ['user' => $user]);
}

In view:
{{$user}} and data you need like {{$user->name}} etc.
Example for multiple users with routes per function above:
public function index()
{

$users = User::paginate(10);

return view('user.list', ['users' => $users]);
}

Then in the view you can list with links by type:
<ul>
@foreach ($users as $user)
<li><a href="route('user.show', ['id' => $user->id])">{{$user->name}}</a></li>
@endforeach
</ul>

On the other hand, you formed a question that makes it difficult to understand what you need. If you have one user, then the list of users will be from one user - you. The example above is the default exhaustive code for an example between listing users and displaying the profile of one. Dare, find out and form a question that can be answered definitely.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question