简体   繁体   English

PUT&DELETE请求 - 共享主机上的Laravel应用程序

[英]PUT & DELETE requests - Laravel app on a shared hosting

I've made a laravel cms app which I'm trying to deploy on a shared hosting. 我已经制作了一个laravel cms应用程序,我正在尝试在共享主机上部署。 Locally, it runs great. 在当地,它运行良好。

I've saved all laravel app files/folders (except public) in the root under 'adminCore' folder. 我已经在“adminCore”文件夹下的根目录中保存了所有laravel应用程序文件/文件夹(public除外)。 Then, I've copied all laravel's public folder content to public_html/test_page folder. 然后,我将所有laravel的公用文件夹内容复制到public_html / test_page文件夹中。

When I run it (testpage.mywebpage.com), I can log in, I can 'see' all views, connect and read from the database - I can even store new data. 当我运行它(testpage.mywebpage.com)时,我可以登录,我可以“看到”所有视图,连接并从数据库中读取 - 我甚至可以存储新数据。 However, if I try to edit or delete, data (from database), I get a 403 error, ie PUT and DELETE requests get denied. 但是,如果我尝试编辑或删除数据(来自数据库),我会收到403错误,即PUT和DELETE请求被拒绝。

Since I'm fairly new to this problematics, I'd really appreciate if you could explain why is this happening and/or how should this be solved. 由于我对这个问题很新,我真的很感激你能解释为什么会发生这种情况和/或如何解决这个问题。 Thank you in advance! 先感谢您!

Laravel doesn't actually use "PUT" and "DELETE" requests in forms. Laravel实际上并没有在表单中使用“PUT”和“DELETE”请求。 Instead, a hidden form field is added to the form when you specify a PUT or DELETE action: 相反,当您指定PUTDELETE操作时,会向表单添加隐藏的表单字段:

<input name="_method" type="hidden" value="PUT">

The issue could be that you're actually using PUT and DELTE as actions in your form, when you should be using a hidden field like above. 问题可能是你实际上使用PUTDELTE作为表单中的动作,当你应该使用上面的隐藏字段时。

The form action should be POST and then then add the hidden _method field with the value of your desired action (as above). 表单action应该是POST ,然后使用所需操作的值添加隐藏的_method字段(如上所示)。 Example: 例:

<form method="POST" action="route/url">
    <input name="_method" type="hidden" value="PUT">
    <!-- other form fields here -->
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM