How To Get IP Address in Dockerized Laravel

Getting a client IP address in Laravel is pretty simple. You don’t need to know which header contains the IP address, because there is the ip() method in the Illuminate\Http\Request class. However, if your Laravel application is running in a Docker container with virtual network, the method above will always return Docker internal IP address … Read more

How to Fix Permission Denied in Laravel

After deploying a new project or executing artisan commands on the server, you can encounter permission denied error in Laravel when it attempts to write logs or cache. Misconfigured write permissions or ownership on the storage directory cause this issue. In this short article, I will explain why it happens, how to fix it, and … Read more

How to Pass PHP Variable to JavaScript in Laravel

Sometimes, you may need to pass certain PHP variables to JavaScript code in a Blade template or even to a separate JavaScript file that is imported into the template. In this short article, I will show you how to pass PHP variable to JavaScript in Laravel and avoid errors in the JavaScript console. How to … Read more

How to Fix Job Timed Out in Laravel

If you use queues in Laravel, you most likely encountered the Job has timed out error when processing jobs in a queue. In older versions of Laravel you can see this error message directly in the terminal or the failed_jobs database table after the job has failed when job is running longer than 60 seconds. … Read more

How to Run Laravel Scheduler in Docker

In this short article, I will show how to run scheduled cron jobs in Laravel for an application that is deployed in a Docker container. The most proper way would be to run cron directly in a separate container and process that job there. But this will increase the load on the system and resource … Read more

How to Debug Laravel Application

If you’re developing a complex and robust application, you may encounter unexpected behavior that requires, debugging to find the root cause. While traditional debugging techniques such as Xdebug, breakpoints, and step-by-step execution are helpful, they can be time-consuming and unnecessary in many cases. One of the most popular ways to debug code is by printing … Read more

How to Change Column in Migration Laravel

Laravel allows developers to use migrations for creating database tables. However, it’s not always easy to determine in advance which columns will be needed in the future or what type of data they will store. Consequently, rarely you may want to change a column name or even its data type. You can use the renameColumn() … Read more

How to Get Route Name in Laravel

Every route in Laravel can have a name, which you can use to create URLs in your controllers with the route() helper. Sometimes you may want to find the current route name or a name of a route for a specific action. In this short article, we’ll explore how to get route name in Laravel … Read more

How to Return Exception as JSON in Laravel

Laravel has different default exceptions. For example ValidationException, AuthenticationException, NotFoundHttpException, etc. Each exception can be handled and rendered for user by its own way. For example, NotFoundHttpException usually is converted to beautiful 404 page. It is not so bad, but when AuthenticationException is thrown, Laravel just redirect user to the login page. This may work … Read more

How to Run a Specific Test in Laravel

Laravel framework allows you to run tests using the artisan command since the 7.1.1 version. But it runs all available tests. If you want to run a specific test file or a specific test case, you should use additional options. In this short article, I will explain how to run a specific test in Laravel … Read more