How to Use Precognition in Laravel 9

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. In some … Read more

How to Use Where() in Laravel

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 … Read more

How to Create Model in Laravel

Models in Laravel provide a simple interface for interacting with the database. A model can help create a new record in the database and find needed records. But first, you have to create a model class and configure it properly. In this article we will dive into how to create model in Laravel. We will … Read more

How to Use CORS 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, … Read more

How to Run Raw SQL Query in Laravel

Laravel has an excellent query builder, that can help build very complicated queries. But in some cases you may want to use a new functionality or a specific methods of you database. In this case you should use raw SQL queries. It is possible. You can create entire SQL query from scratch or use raw … Read more

How to Fix Indirect Modification of Overloaded Property Has no Effect 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. But the problem is that you can’t modify properties accessed by magic methods. … Read more

How to Use Elasticsearch in Laravel

ElasticSearch is one of the most popular Open-Source search engines. It supports not only searching but also very complicated data filtering and data aggregating. If you develop online stores or blogs, you need to integrate the search feature in Laravel. Of course, you can use the official ElasticSearch client package and do everything by yourself, … Read more

How to Fix Array to String Conversion in Laravel

You can come across this exception when you try to write an array into the string variable. In most cases, there is a simple solution. Just convert the array into a string using implode(), print_r() or json_encode() methods. In this article, we will explain how to fix the array to string conversion exception in Laravel. … Read more

How to Get ENV Variable in Laravel

Laravel uses an .env file to configure environment-specific variables for the application. For example URL, database connection, queues, Redis connection, external services, etc. You can add your own environment variables and use them in your code. In this short article we will explain how to get the env variable in Laravel in the blade or … Read more

How to Get Raw SQL Query in Laravel

Laravel has an excellent query builder called Eloquent. It supporting complicated where combinations, grouping, ordering, joins, a lot of types relation and other things. So you can cover 90% of your requirements using Eloquent and not to write raw SQL code. But when you have troubles with Eloquent queries you may want show raw SQL … Read more