2016-01-25 36 views
0

我想檢查用戶是否登錄,如果是的話顯示一些內容,否則我想單擊一個URL或調用模態。Laravel 5有條件地觸發模態

@if(Auth::check()) 
    .............if user registered display here 
@else 
    I want to click the link below automatically....OR Call a view 
    <a class="signin_link" href="{{ action('Auth\[email protected]') }}" rel="get:Loginform"><i class="fa fa-user" style="font-size:20px"></i></a> 
@endif 

回答

1

這會將用戶重定向到的頁面,你想:

@if(Auth::check()) 
    .............if user registered display here 
@else 
    //Redirect user to the link 
    <script>window.location = "{{ action('Auth\[email protected]') }}";</script> 
@endif 

,這將打開你的模式,如果使用的是引導例如:

@if(Auth::check()) 
    .............if user registered display here 
@else 
    //Opening a bootstrap modal 
    <script>$('#myModal').modal('show')</script> 
@endif 

注意 :我假設你已經在你的頁面上有你的模態html

0

雖然你可以做到這一點,你不應該。而應使用auth中間件(請參閱)。

下面是一個例子:

Route::group(['middleware' => 'auth'], function() { 
    Route::get('/this/route/needs/a/logged/in/user', '[email protected]'); 
}); 

如果沒有用戶登錄訪問者重定向到登錄頁面(您可以在中間件中設置)。