How to Download File from URL in PHP

Downloading files is a very common task. You may need to do this when you want to import data from another site, download a backup, and so on. There are multiple methods you can use to download a file. You can use the built-in file_get_contents() function which fetches the contents of any file into a … 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 Get Domain From URL in PHP

Sometimes, you may need to extract the domain or some other parts from an URL. It is a very straightforward task that can be done using the built-in parse_url() function without any external libraries. However, third-party libraries can provide more convenience and power to handle URLs In this short article, I will show how to … 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 Fix TokenMissmatch Exception in Laravel

The TokenMissmatchException can appear when you send any POST request to a web route without a CSRF protection token or with an outdated one. CSRF protection is enabled for all web routes by default. It is required to protect your forms from malicious actions. In this article, I will show multiple cases when you can … 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

Top 8 Useful Symfony Packages

Symfony is a popular framework for the PHP language that has its own dedicated composer plugins and bundles designed for use within the Symfony ecosystem. However, It can be challenging to integrate them into other projects. Fortunately, Symfony also has many simple independent packages that can be installed using composer in any project, making your … 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 Read XLSX File Into Array

Sometimes you may need to import some data from an XLSX file into your application. The first step is to load data from the file into an array. There are a few libraries that can help with this. Each library has its advantages and disadvantages and may be the best solution in a specific case. … Read more

How to Use Where Like in Laravel

Filtering using WHERE with the LIKE operator is very popular in SQL queries. You can use it to find records containing some words or symbols in the database. But Laravel does not have a dedicated method for this operator. Thus, you should use the where() method and specify the operator. In this short article, I … Read more