Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add blade directive @guest #20114

Merged
merged 4 commits into from
Jul 18, 2017
Merged

Add blade directive @guest #20114

merged 4 commits into from
Jul 18, 2017

Conversation

LKaemmerling
Copy link

As addition to #20087 it would be nice if there is the opposite of @auth, so i implemented it.

@it-can
Copy link
Contributor

it-can commented Jul 18, 2017

If do not pass a guard, will this work?

@m1guelpf
Copy link
Contributor

@it-can Yes

@LKaemmerling
Copy link
Author

@it-can yeah it will, it is the same code as #20087. @m1guelpf what do you thing if the @guest can be an "else" for your @auth ?

Like:

@auth

//Is authentificated

@guest 


// Is guest 

@endauth

@m1guelpf
Copy link
Contributor

m1guelpf commented Jul 18, 2017

@LKDevelopment That'd be confusing. I'd suggest keeping both PR's as-is, as making the @guest directive work as an else would be confusing if you only want to use guest...

@it-can
Copy link
Contributor

it-can commented Jul 18, 2017

@LKDevelopment If I add a custom directive to my laravel 5.4 app, I get a error when calling

AppServiceProvider.php

Blade::directive('auth', function ($guard = null) {
    return "<?php if(auth()->guard{$guard}->check()): ?>";
});
        
Blade::directive('endauth', function () {
    return "<?php endif; ?>";
});

This gives an error

@auth
    logged in
@endauth

Undefined property: Illuminate\Auth\AuthManager::$guard

compiles to:

<?php if(auth()->guard->check()): ?>
logged in
<?php endif; ?>

this works...

@auth('web')
    logged in
@endauth

@m1guelpf
Copy link
Contributor

@it-can You have a typo in the directive.
Try this:

Blade::directive('auth', function ($guard = null) {
    return "<?php if(auth()->guard({$guard})->check()): ?>";
});
        
Blade::directive('endauth', function () {
    return "<?php endif; ?>";
});

@it-can
Copy link
Contributor

it-can commented Jul 18, 2017

@m1guelpf yes that works... but when I check this PR, the code is missing the parenthesis?

*/
protected function compileGuest($guard = null)
{
return "<?php if(auth()->guard{$guard}->guest()): ?>";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be changed in #20087 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems taylor changed it...

a11b44a

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No guys!
This is not the guard which is passed, but the complete $expression, with the ().
Nothing to change here!

Copy link
Contributor

@m1guelpf m1guelpf Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mathieutu is rigth. There's nothing to change here.

@@ -119,4 +119,25 @@ protected function compileEndAuth()
{
return '<?php endif; ?>';
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the extra whitespace here, and your PR is perfect!

@taylorotwell taylorotwell merged commit c41fb3a into laravel:5.4 Jul 18, 2017
@m1guelpf m1guelpf deleted the Add-Blade-Directive-guest branch July 18, 2017 13:14
@carusogabriel
Copy link
Contributor

carusogabriel commented Aug 10, 2017

@m1guelpf @LKDevelopment Any ideas to work in @LKDevelopment's proposal?

@auth
    // Is authenticated
@guest 
    // Is guest 
@endauth

@m1guelpf
Copy link
Contributor

@Gabriel-Caruso I don't think so. Now it'd be a breaking change...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants