If you use laravel auth, you can put this in your controller:
// Get the currently authenticated user...
$user = Auth::user(); // pass $user to your view
and in your view:
Hi $user->name. Welcome to your dashboard.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
So I'm trying to have the dashboard page after the user logs in to display user-specific information about them. Like for instance, I would like the page to say "Hi [name of user as displayed in the database]". Any tips about how I should go about this?
This is how my blade file looks:
@extends('layouts.auth')
@section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Dashboard</div>
<div class="card-body">
Hi volunteer organisation. Welcome to your dashboard.
<p>Click here to view a list of volunteers who are interested in your cause.</p>
</div>
</div>
</div>
</div>
</div>
@endsection
If you use laravel auth, you can put this in your controller:
// Get the currently authenticated user...
$user = Auth::user(); // pass $user to your view
and in your view:
Hi $user->name. Welcome to your dashboard.
@ARTHVRIAN - Do you mean in my auth.php file?
I added it to VolOrgController.php and it didn't pull the info.
@ARTHVRIAN - I understand what the information is saying, however, I am still clueless as to what controller to input the line of code in. I tried the LoginController and still nothing.
No, In your LoginController not, I assume that the view in first post shows after login, you must put the code in the controller of that view
or you can try in your view
Hi {{ Auth::user()->name }}}. Welcome to your dashboard.
So I'm trying to have the dashboard page after the user logs in to display user-specific information about them.
Since you know they're logged in, just access the logged in user instance in the view.
Hi, {{ auth()->user()->name }}. Welcome to your dashboard.
@CRONIX - Now I'm getting the error message: "Trying to get property of non-object (View: /Applications/MAMP/htdocs/V2O/resources/views/volorg.blade.php)"
That would happen if the person isn't actually logged in, since user() wouldn't exist and would be null.
Is the route you're accessing to display the profile using the auth middleware?
@CRONIX - Do you mean my web.php file? If so, this is what it looks like:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Displays welcome page
/*
Route::get('/', function () {
return view('welcome');
});
*/
Route::view('/', 'welcome');
Auth::routes();
Route::get('/login/volorg', 'Auth\LoginController@showVolorgLoginForm');
//Route::get('/register/volorg', 'Auth\RegisterController@showVolorgRegisterForm');
Route::post('/login/volorg', 'Auth\LoginController@volorgLogin');
//Route::post('/register/volorg', 'Auth\RegisterController@createAdmin');
Route::view('/home', 'home')->middleware('auth');
Route::view('/volorg', 'volorg');
Route::resource('interest','InterestController');
Route::resource('vo','VoController');
Route::resource('volunteer','VolunteerController');
Route::get('volunteer/show/{id}', 'VolunteerController@show');
//Auth::routes();
//Route::get('/home', 'HomeController@index')->name('home');
//Auth::routes();
//Route::get('/home', 'HomeController@index')->name('home');
//Auth::routes();
//Route::get('/home', 'HomeController@index')->name('home');
//Auth::routes();
//Route::get('/home', 'HomeController@index')->name('home');
Yes, but which route is being used here? There's only one using the auth middleware, /home.
@CRONIX - The volorg view is being used here. I added :
Route::view('/volorg', 'volorg')->middleware('auth');
to the file and now it won't load at all. It's telling me too many redirects :(
@larasande Cant your use something like this? Your Controller setup
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
public function volorgLogin(Request $request){
//if user logins with email.
//find the required user
$data = $request->only('email','password');
$user = User::where('email', $data['email'])->first();
//Hash check if matches input password returns true or false
$checkPassword = Hash::check($data['password'], $user->password);
if($checkPassword){
auth()->login($user);
//here return view with your $user data
}
}
public function showVolorgLoginForm(){
if(Auth::check(){
//If User is logged in already return to dashboard or something
return redirect()->route('home');
}
return view('your View name');
}
}
@USAANDI - This is my LoginController
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
$this->middleware('guest:volorg')->except('logout');
}
public function guard()
{
return Auth::guard('volorg');
}
public function showVolorgLoginForm()
{
return view('auth.login', ['url' => 'volorg']);
}
public function volorgLogin(Request $request)
{
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
if (Auth::guard('volorg')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {
return redirect()->intended('/volorg');
}
return back()->withInput($request->only('email', 'remember'));
}
}
@larasande Have you set up your Database?
I guess you ran command.
php artisan make:auth
But you need run this too
php artisan migrate
to migrate your DB
i suggest to read https://laravel.com/docs/5.7/authentication if you have not already done that.
You can try this too
$credentials = $request->only('email', 'password');
if (Auth::attempt($credentials)) {
// Authentication passed...
return view('/home')
}
@USAANDI - Yep, I have done all of that..even read the documentation.
I don't get why it's telling me too many redirects.
@LARASANDE - basically it is trying to get to auth website but it can't and it is redirecting to another page but because that page is auth it fails and redirects again.
Basically you'll have endless loop if you see what i mean. That is why you get that. Too many redirects
Please or to participate in this conversation.