Home > OS >  Laravel deployed on Azure WebApp cannot post or update to Azure SQL database
Laravel deployed on Azure WebApp cannot post or update to Azure SQL database

Time:10-09

I have successfully created a test Laravel project following a tutorial I found on the internet and which I tested locally with XAMPP. It is working just fine with MySQL, but I need to set this website with Azure SQL Database and deploy it to Azure WebApp service. Deployment is done through Azure DevOps pipeline and all is good, working as a charm, but when I open the site and try to create a user it just doesn't create it inside of the database even though the Azure SQL server is connected to the Azure WebApp and Laravel itself is also connected. I know about the Azure MySQL flexible server option, but I have to do it with Azure SQL server speciffically, so any suggestions on the matter would be appreciated.

Specs: Laravel v9.32.0 /
PHP v8.0.19 / NGINX v1.22.0 / OS: Debian GNU/Linux 10 (buster)

Here are some screen shots that I think might be useful:

1.) This is the list of users loaded from the Azure SQL database - img1

2.) This is the form when I am trying to edit/update a user - img2

3.) This is the current route list - img3

4.) This is the contact form HTML - img4

5.) This is the Laravel Controller where the magic happens - img5

6.) This is the Laravel Model - img6

7.) This is the web.php Route - img7

In addition to all of that, I would like to mention that the I have allowed the WebApp service on the Azure SQL server firewall, so as my IP address (even though I don't find it necessary for this purpose). But I am using a plain text password which I know is not the best way to connect to the Azure SQL server, but is working with the connection string. So I have a suspect that this might be a thing but I am not sure how to deal with that...

CodePudding user response:

After few days of research I found out that the problem was caused by the CSRF token. It looks like when it is disabled/commented within the /app/Http/Kernel.php writing to the SQL database is possible. That is one workaround which is not recommended because you could expose your website to XSS attacks.

The recommended is to simply use SSL certificate and run your Laravel website through https://. This way the requests are going through without any issues.

  • Related