Reputation: 657
I am making a laravel app that must have a public user profile page. The profile page that I currently have is a private one. How can I make the page public so that all the users can view all the profiles.
Here is the code:-
In routes -> web.php
Route::get('user/profile', 'UserProfileController@profile')->name('user.profile');
In Http-> Controllers-> UserProfileController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserProfileController extends Controller
{
//
public function __construct()
{
$this->middleware('auth');
}
public function profile()
{
return view('user.profile');
}
}
In View -> user -> profile.blade.php
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 offset-md-1">
<div class="card">
<div class="card-header">{{ Auth::user()->name }}'s Profile page</div>
<div class="card-body">
Hi, {{ Auth::user()->name }} This is a private profile page!!!
</div>
</div>
</div>
</div>
</div>
@endsection
Upvotes: 0
Views: 1059
Reputation: 121
add user id
<a href="{{ route('user.profile', auth()->user()->id )}}"></a>
Upvotes: 1
Reputation: 121
01. change router to
Route::get('user/profile/{id}', 'UserProfileController@profile')->name('user.profile');
02. in UserProfileController profile($id) method pass $id and middleware add except
use App\User;
class UserProfileController extends Controller
{
//
public function __construct()
{
$this->middleware('auth', ['except' => [ 'profile']]);
}
public function profile($id)
{
$user = User::find($id);
return view('user.profile', compact('user') );
}
}
**03. In View -> user -> profile.blade.php **
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-10 offset-md-1">
<div class="card">
<div class="card-header">{{ $user->name }}'s Profile page</div>
<div class="card-body">
Hi, {{ $user->name }} This is a private profile page!!!
</div>
</div>
</div>
</div>
</div>
@endsection
Upvotes: 1