Super Sale Limited Time 50% OFF for All-Access Plans
Save 50% Now

"profile_photo_url" on null


I just installed a fresh copy of the starter kit for Metronic Laravel (v8.3.2)
Attempt to read property "profile_photo_url" on null
detailed error message is there
Any help?


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


Hi Eladl Eltanahy

The issue is that the routes are not protected by authentication middleware, allowing unauthenticated users to access views that expect a logged-in user. Here are the steps to fix this:

The main issue is in routes/web.php file. The authentication middleware is currently commented out. Uncomment and properly configure it:

// In routes/web.php, change this:
// Route::middleware(["auth", "verified"])->group(function () {
// Route::get("/", [DashboardController::class, "index"]);
// Route::get("/dashboard", [DashboardController::class, "index"])->name("dashboard");
// // ... other routes
// });

// To this:
Route::middleware(["auth", "verified"])->group(function () {
Route::get("/", [DashboardController::class, "index"]);
Route::get("/dashboard", [DashboardController::class, "index"])->name("dashboard");

Route::name("user-management.")->group(function () {
Route::resource("/user-management/users", UserManagementController::class);
Route::resource("/user-management/roles", RoleManagementController::class);
Route::resource("/user-management/permissions", PermissionManagementController::class);
});
});


add null safety checks to your Blade templates. In the navbar files, update the code:

@if(Auth::check() && Auth::user()->profile_photo_url)
<img src="{{ \Auth::user()->profile_photo_url }}" class="rounded-3" alt="user" />
@else
<div class="symbol-label fs-3 {{ app(\App\Actions\GetThemeType::class)->handle("bg-light-? text-?", Auth::user()->name ?? "U") }}">
{{ substr(Auth::user()->name ?? "User", 0, 1) }}
</div>
@endif


We will fix it.

Thanks



C:\Laravel\starterkit\resources\views\layout\partials\sidebar-layout\header\_navbar.blade
.php : 43


@if(Auth::user()->profile_photo_url)

<img src="{{ \Auth::user()->profile_photo_url }}" class="rounded-3" alt="user" />

@else

<div class="symbol-label fs-3 {{ app(\App\Actions\GetThemeType::class)->handle('bg-light-? text-?', Auth::user()->name) }}">

{{ substr(Auth::user()->name, 0, 1) }}

</div>

@endif


Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Click any option to insert into your comment. Select text first to wrap it.
  • **text** to make things bold
  • *text* to emphasize
  • ### Heading to make headings
  • [link text](url) for links
  • ![alt text](image-url) to paste in an image
  • - item to make a list
  • 1. item to make an ordered list
  • > quote to quote somebody
  • `code` for single line of code
  • ```js ... ``` for JS code block
  • ```html ... ``` for HTML code block
  • ```scss ... ``` for SCSS code block
  • ```php ... ``` for PHP code block
  • --- for a horizontal rule
  • happy  :)
  • shocked  :|
  • sad  :(