首页 > 解决方案 > how to hit an api on button click using laravel

问题描述

i am new to working with API ,i have 2 buttons in my view file and i want to print the sheet which is available as an API ,

 <div class="card">
        <div class="card-body">
            @include('admin.inc.messages')
            <div class="row justify-content-center">
                <div class="col-md-4">
                    <button type="button" class="btn btn-primary btn-block">Back</button>
                    <button type="button" class="btn btn-primary btn-block">Print Airway Bill</button>
                    <button type="button" class="btn btn-primary btn-block">Print Invoice</button>
                </div>
            </div>
        </div>
    </div>

i have got the path , i want to ask where should i define the path for that , in the web.php or api.php and second thing how should i give the path in the buttons

any help will be appreciated !

标签: laravelapi

解决方案


您很可能需要使用自己的 api,或者使用 ajax 请求。这可以通过护照来完成,在文档中可以看到。如果您愿意,您可以随时绕过,但是您将无法使用中间件处理这些请求。这意味着,您的项目将面临潜在的安全风险,因为请求不会受到路由中间件的影响。在某些方面保护和帮助您。

例如,如果您无法针对中间件进行身份验证,您将无法确定哪个/什么用户正在请求数据。另一个比较可能是针对用户登录的能力,但无法通过应用程序页面知道哪个用户已通过身份验证。这与您登录 stackoverflow 时的情况相当,您显然可以在右上角看到您的用户信息/个人资料以及您的图片等……如果您绕过,您将没有该能力。

因此,我强烈建议您访问上面发布的链接,并考虑使用您自己的 api 或创建一个服务来这样做。


推荐阅读