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

Conversation

Projects
None yet
6 participants
@LKaemmerling

LKaemmerling commented Jul 18, 2017

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

Lukas Kämmerling added some commits Jul 18, 2017

Lukas Kämmerling
Lukas Kämmerling
Lukas Kämmerling
@it-can

This comment has been minimized.

Show comment
Hide comment
@it-can

it-can Jul 18, 2017

Contributor

If do not pass a guard, will this work?

Contributor

it-can commented Jul 18, 2017

If do not pass a guard, will this work?

@m1guelpf

This comment has been minimized.

Show comment
Hide comment
@m1guelpf

m1guelpf Jul 18, 2017

Contributor

@it-can Yes

Contributor

m1guelpf commented Jul 18, 2017

@it-can Yes

@LKaemmerling

This comment has been minimized.

Show comment
Hide comment
@LKaemmerling

LKaemmerling Jul 18, 2017

@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

LKaemmerling commented Jul 18, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@m1guelpf

m1guelpf Jul 18, 2017

Contributor

@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...

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

This comment has been minimized.

Show comment
Hide comment
@it-can

it-can Jul 18, 2017

Contributor

@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
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

This comment has been minimized.

Show comment
Hide comment
@m1guelpf

m1guelpf Jul 18, 2017

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; ?>";
});
Contributor

m1guelpf commented Jul 18, 2017

@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

This comment has been minimized.

Show comment
Hide comment
@it-can

it-can Jul 18, 2017

Contributor

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

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()): ?>";

This comment has been minimized.

@it-can

it-can Jul 18, 2017

Contributor

should this also be changed in #20087 ?

@it-can

it-can Jul 18, 2017

Contributor

should this also be changed in #20087 ?

This comment has been minimized.

@it-can

it-can Jul 18, 2017

Contributor

Seems taylor changed it...

a11b44a

@it-can

it-can Jul 18, 2017

Contributor

Seems taylor changed it...

a11b44a

This comment has been minimized.

@mathieutu

mathieutu Jul 18, 2017

Contributor

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

@mathieutu

mathieutu Jul 18, 2017

Contributor

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

This comment has been minimized.

@m1guelpf

m1guelpf Jul 18, 2017

Contributor

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

@m1guelpf

m1guelpf Jul 18, 2017

Contributor

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

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

This comment has been minimized.

@m1guelpf

m1guelpf Jul 18, 2017

Contributor

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

@m1guelpf

m1guelpf Jul 18, 2017

Contributor

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

@taylorotwell taylorotwell merged commit c41fb3a into laravel:5.4 Jul 18, 2017

1 of 2 checks passed

continuous-integration/styleci/pr The StyleCI analysis has failed - 1 file needs addressing
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@m1guelpf m1guelpf deleted the LKaemmerling:Add-Blade-Directive-guest branch Jul 18, 2017

@carusogabriel

This comment has been minimized.

Show comment
Hide comment
@carusogabriel

carusogabriel Aug 10, 2017

Contributor

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

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

carusogabriel commented Aug 10, 2017

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

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

This comment has been minimized.

Show comment
Hide comment
@m1guelpf

m1guelpf Aug 10, 2017

Contributor

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

Contributor

m1guelpf commented Aug 10, 2017

@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