Category: Laravel

[Tip] Connect to multiple databases on the Fly with Lumen

Its not always an easy way to connect to different database if the configuration files does not include any information about it, in older version it was even a tricky one, especially if you have a bit of relationship that you want to use.

Don’t understand from my words that you cant do that, but it was not a direct use of setConnection , from my memory, the setConnection function used to force the connection on the current model only not the children nor any other one that it has a relationship with, when the info for this connection was not part of the database config file.

Things has changed and now in Lumen 5.5 (I didn’t try it with older version), as now you can use the function on to enforce the connection on the Model and any relationship it needs. like the following:

Create a base Model and create a function within called mergeConnections:

Continue reading

Filed under: Code, Laravel, PHP

How to test your Laravel application with Bitbucket Pipelines

Bitbucket Pipelines is a CI service that you can use to test your application, yes it has its own limitation, but remember it is still new and hopefully it will get better. Today I had the chance to work with it, and trust me I was not planning to do so, am a happy Gitlab-ci user, but why not.

Each of these service has its pros and cons, and am not planning to go over it and list it, just do a small reading to find the differences, so today I’ll talk about how to test your Laravel Application with Bitbucket Pipelines and how you can get it fast.

Requirements:

For sure you need to know Laravel and how to write tests, this post will not talk about it, and it would be nice if you know a little bit of Docker.

Enabling Pipelines:

You will need to enable the pipelines from the Repository Settings as the following image

Continue reading

Filed under: Code, docker, Laravel, PHP

How to test and auto deploy your laravel code from Gitlab

Few days ago, I was playing with the new Laravel 5.4 and Gitlab CI, and got to the point where I wanted the CI to test my code once I push it.

Using google lead me to this post on Laracasts, and it was the starting point for me, there you can get important files .gitlab-ci.yml and .gitlab-ci.sh  , basically the first one will define the stages for the testing and the second one will build the environment for your test.

So lets look at a short version of .gitlab-ci.yml

Continue reading

Filed under: Business, Code, docker, Laravel, Linux, MySQL, PHP

Books I need to finish this month or so

This is just a small list of all the books which I was reading and planing to finish them ASAP, they are hanging and I cant figure out a correct time to finish them so hopefully listing them here will help me do it.

  1. Laravel Code Smart ( https://leanpub.com/codesmart/ )
  2. Easy E-Commerce Using Laravel and Stripe ( https://leanpub.com/easyecommerce )
  3. Domain-Driven Design in PHP ( https://leanpub.com/ddd-in-php )
  4. Servers for Hackers ( https://leanpub.com/serversforhackers ) [finished the old one, need to read the new release :( ]

I have started reading only the first and the second book ( sadly ), but am planing to finish and go to finish the list by the end of the next month or so ..

 

Filed under: Books, Code, Laravel, Linux, Nginx, PHP

Fix “HTTP Error 413 Request entity too large” problem

Yesterday Jeff Madsen has sent a small Laravel tip which address how you can validate the post size for your uploaded data via Laravel middleware called VerifyPostSize.

Even though the solution is valid when you have no control over your server, but when you do, you should fix the base of the problem which is your web server (in my case its Nginx ).

Normal when you upload a file, the process looks like this :

webservers

1- The user request the website

2- The Server get the request first and forward it to PHP process.

3- PHP process do the magic and response back to the Server.

and the data get back from 3 to 1 .

Now as I said the solution which was provided solve the problem at the PHP processes level not at the Web server, at the end the data need to go through the server first.

In nginx documentation we have a core module which control the size of the data which the client can send through the server, the default size is 1Mb, so to fix this problem you need to do the following:

1- edit the file /etc/nginx/nginx.conf and make sure that  the value for client_max_body_size is big enough like:

2- edit your php.ini file to make sure that you have setup the upload size and memory with big values like :

lastly you need to restart nginx.

now just a small note, you will need to adjust the values based on your needs, there are no magic values which can solve your issue here.

If you find that this information is incorrect, please let me know via email z[At]zah.me or via contact page I’ll be happy to get more information about this topics from experienced people out there.

PS: as usual, since english is not my mother language, you might find some errors, so if you do let me know and I will be happy to fix it.

Filed under: Code, Laravel, Linux, Nginx, PHP