New Metronic Docs!Added Integration Docs with Starter Kits Apps for Laravel, Laravel Livewire, Angular, Vue, Symfony, Blazor Server, Django & Flask & more
Browse Docs

"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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • 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
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(