问题描述
我是 Laravel 新手,如何在 Blade 中自动调用路由这里是 Laravel 中使用 Laravel 8 的代码
@if($activity_type=='General-Activity')
{{ (route('support.direction',$activity_id)) }}
@endif
让我在 Laravelblade 中解释我想检查 $activity_type=='General-Activity' 是否路由 support.direction 并传递一个值我使用上面的代码它只打印这个 http://localhost:8000/progress/方向/21c73354-5158-4697-98cb-066800d16e03 我不知道如何自动路由而不是通过点击使用
解决方法
我假设您正在尝试在条件为真时自动重定向用户。您可以使用带有 switch
的 JavaScript
案例来处理重定向过程。例如。如果 URI 是 www.example.com/xyz
,则通过使用 echo url()->current();
访问当前页面 url 来获取请求。这将输出请求并使用 switch case 来处理重定向过程。例如,这里是 Laravel 中的示例代码。
{{ $url = url()->current(); }}
@switch($url)
@case('foo')
First case...
<script>
<!-- simulate the script with a mouse click or http redirect -->
// Simulate a mouse click:
window.location.href = "http://www.w3schools.com";
// Simulate an HTTP redirect:
window.location.replace("http://www.w3schools.com");
</script>
@break
@case('baz')
Second case...
<script>
<!-- simulate the script with a mouse click or http redirect -->
// Simulate a mouse click:
window.location.href = "http://www.w3schools.com";
// Simulate an HTTP redirect:
window.location.replace("http://www.w3schools.com");
</script>
@break
@default
Default case...
@endswitch