Reputation: 247
i have view page
@if((Voyager::can('delete_'.$dataType->name))||(Voyager::can('edit_'.$dataType->name))||(Voyager::can('browse_'.$dataType->name)))
some function here
@elseif
return Redirect::to('404page') @endif
error
ErrorException in VerifyCsrfToken.php line 156: Trying to get property of non-object
else condition code is not working.How can i return inside from one to another.any help would be appreciated.
Upvotes: 0
Views: 143
Reputation: 40663
You can't use a redirect response in a view. A redirect response is a response with code 3XX. Response codes are part of the header, but you can only send the headers once. To send view data you need to have already sent the headers therefore you can no longer return a redirect response. You can however use JavaScript:
@if((Voyager::can('delete_'.$dataType->name))||(Voyager::can('edit_'.$dataType->name))||(Voyager::can('browse_'.$dataType->name)))
some function here
@else
<script> window.location.href = "{!! url()->to('404page') !!}"; </script>
@endif
Note that this will actually load the page and the user might prevent the redirect from happening so don't show anything restricted.
Ideally you'd need to return the redirect response before the view in the controller or middleware
Upvotes: 1
Reputation: 2416
Change @elseif
to @else
@if((Voyager::can('delete_'.$dataType->name))||(Voyager::can('edit_'.$dataType->name))||(Voyager::can('browse_'.$dataType->name)))
//
@else
Redirect::to('404page')
@endif
And user redirect()
instead of Redirect::to
. Or if you want to send a user to 404 error page, use abort('404')
.
Upvotes: 1