D
D
David2016-06-16 01:22:05
Laravel
David, 2016-06-16 01:22:05

Is this approach normal practice for Laravel?

Good day.
The site has a dynamic menu. For example, while the user is not logged in, the "Register" button is visible to him, and after authorization it disappears. Is it good practice to check if the user is logged in right in the view? Or are there ways to implement such manipulations somehow more beautifully?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
ValeRa2, 2016-06-16
@MiragePresent

Here is the correct solution. Use Blade.
@unless (Auth::check())
You are not signed in.
@endunless
This is from the documentation:
https://laravel.com/docs/master/blade

S
Sergey, 2016-06-16
Protko @Fesor

Is it good practice to check if the user is logged in right in the view?

Depends on how you do it. In general, this is presentational logic, so it is quite possible.

W
WebDev, 2016-06-26
@kirill-93

<?php if(!\Illuminate\Support\Facades\Auth::check()) {?>

I guess you're confused by the long namespace.
You can write
Get shorter and prettier:
@if (auth()->check())
Зарегистрироваться
@endif

It is correct to check in this way in the view.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question