Similar ideas popular now
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 string, or you can use an external library that is called cURL. This library can download a remote file directly to a file in your file system.
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. In this article, I will explain how to enable debugging in Laravel, how to use it’s built-in features, and how to simplify debugging with additional packages.
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 get domain from URL in PHP using both the built-in function and object-oriented third-party libraries.
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() method to rename columns, and the change() method to update their properties. In this article, I will show how to change column in Laravel migration in detail.
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 encounter the exception and explain how to fix TokenMissmatch exception 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 for both cases as well as how to create a URL for an action without using the route name.
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 code more readable, standardized, and faster.
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. It works pretty well for web, but when it happens for API routes, it can eat a lot of time for troubleshooting.
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. In this article, I will show how to read XLSX file into array using PHPSpreadsheet and OpenSpout.
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 will explain how to use where like 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 using the filtering features of the PHPUnit framework.
Laravel supports the encryption of fields in database tables and passwords. But you must set the encryption key in the APP_KEY environment variable. If the variable is empty or the key has an invalid format, you will get this error. In this short article, I will explain how to fix the “your app key is missing or no application encryption key has been specified” error in Laravel.
UUID or Universally unique identifier can be used where you need to have some unique string, for example for HTML element identifiers, any tracking identifiers or as a primary key for Eloquent models. By default, Eloquent uses an integer as the primary key, but if this key is visible to visitors, it is better to make it not incremental. UUID is a great solution for this issue.
Laravel developers are constantly adding new features to new versions of the framework. If you want to know whether your installation supports a specific feature, you should know your version of Laravel. This article will show several ways to check the Laravel version in the command line or your code. You can use the artisan command, the app() helper, or just get the version from Composer.
Composer is a package manager for PHP programming language. You can use it to install or update packages, manage their dependencies, and a lot of other things. By default, Composer installs the latest version of a required package. But you can install any specific version which you want. In this short article, I will show you how to install a specific version of the package using Composer.
There are a lot of cases when you might need to measure code execution time. For example, you want to speed up your application and you need to find the slowest part or you want to benchmark several approaches to do something. In this article, I will show you multiple ways to measure execution time in PHP and Laravel with different precision.
As you know, local time depends on the time zone. You can configure the time zone for your system or server, for the PHP instance. Laravel uses the UTC timezone by default. But if you want to use a specific time zone in the Laravel application, you should change the timezone in the Laravel settings. In this short article, I will explain how to change the timezone in Laravel and how to deal with date serialization in Eloquent models.
Laravel framework tries to be more objective-oriented than other frameworks. It has a dependency injection feature that can help create and manage objects more efficiently. But it also has numerous global functions that make programming simpler. These functions are called helpers.
Laravel 9 ties to make your applications more interactive and ships new features for form validation. It is called precognition. You might have seen on some websites that forms are being validated during their completion. For instance, you have finished filling out a field and immediately receive an error message next to it.
Laravel has a powerful database query builder that is called Eloquent. It can help build very complicated SQL queries to the database. The most frequent operation that developers use is WHERE and its combinations with different operators. Eloquent has the where() method that allows doing this. In this article, we will dive into how to use where in Laravel.
CORS (Cross-Origin Resource Sharing) is a mechanism that lets the web server allow or restrict fetching of its resources from other domains. For example, you can allow browsers to fetch your scripts and images only if your site is opened in the browser. If someone tries to insert links to your images on their website, this person will get a CORS error. It is a default behavior. In this article, we will explain how to use CORS in Laravel.
PHP programming language supports adding virtual properties to classes by using magic methods. You can define methods __get() and __set(), which will be called when somebody tries to access non-existent properties. Laravel Eloquent uses this feature to provide access to model attributes.