Attach, detach and sync many-to-many relationships in Laravel
December 1, 2019
There exists four types of relationship associated between models/entities. And they are: One To One, One To Many, Many To One and Many To Many. We’re specifically going to talk about Many To Many relationship and most importantly attach, detach and sync helper methods that are provided in Laravel in this article.
Drop tables, types and views using wipe artisan command in Laravel 6
November 6, 2019
If you’re looking for a quick way to drop all the tables, their types and views and if you’re using Laravel 6.x, you can use this little artisan command called db:wipe
in order to do the same.
Extending class behaviour in Laravel using Macros
November 2, 2019
In this article, I’m going to discuss about the feature in Laravel using which you can extend the functionality of certain Laravel’s core classes without even touching the original codebase. Or in other words, adding methods to the class dynamically.
Adding password confirmation on certain routes in Laravel
October 9, 2019
If you’ve used some well creafted web application, such as GitHub for instance, you might’ve noticed that upon saving sensitive information such as settings or payment details, it asks for the password confirmation before performing the action. This adds the extra layer of security layer and certainly a nice-to-have feature.
How to utilize Capsule to use Eloquent ORM outside Laravel
September 11, 2019
If you love the Laravel as a framework or more specifically its Eloquent ORM like I do then there’s a great chance that you’d like to use this great ORM in your non-Laravel PHP apps as well. And the good news is it’s rather easier than you might think. Laravel provides a standalone pacakge called Capsule which you can use in your own project. It’s a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style ORM, and schema builder. It currently supports MySQL, Postgres, SQL Server, and SQLite.
Using Lazy Collections on memory-hungry operations in Laravel 6
September 4, 2019
Laravel team has recently released v6.0
of the framework and with this they have added a bunch of exciting new features. Among which, I’m going to talk about Lazy Collections in this article. In Laravel, Illuminate\Support\Collection
class provides a fluent, convenient wrapper for working with arrays of data. In face, all the Eloquent queries are always returned as Collection
instances. LazyCollection
essentially extends the features of the Collection
class. Let’s talk about them in detail.
Process model records in chunks in Laravel
August 27, 2019
Rate limit route requests in Laravel
August 26, 2019
As backend developers, to make our web application full proof we need to make sure our application is running as efficiently as possible all the time. Otherwise, everyone using your database will suffer from slow performance. API limiting, which is also known as rate limiting, is an essential component of Internet security, as DoS attacks can tank a server with unlimited API requests.
Understanding Constructor and Method dependency injection in Laravel
August 3, 2019
To understand, how dependency injection works in Laravel, let’s jsut get to know what dependency injection actually is, in software engineering.
Serialize Closures in PHP using this neat package
July 22, 2019
It’s widely known that PHP can’t serialize closures directly. If you try to serialize a closure in PHP, it will result in a fatal error. Take below for example.
Fetch results based on the existence of the relationship in Laravel Eloquoent
July 12, 2019
If you want to check if the eloquoent model has certain relationship or not and fetch the results accordingly while querying upon it, you can do this by two approaches in the Laravel Eloquent.
Conditional attributes and relationships in Laravel Resources
July 6, 2019
When you’re building an Laravel application which uses APIs at some point, it’s no brainer to use Laravel’s resource classes as it provides the transformation layer that sits between your Eloquent models and the JSON responses that are actually returned to your application’s users.
Re-using query constraints in Laravel Eloquent - Global vs. Local scopes
June 16, 2019
Laravel’s Eloquent ORM comes with this unique set of features called “Scopes” which can be used to re-use some of the query constraints onto all the queries of a certain model. This can be useful to minimize the code while writing the query and is an easy way to make sure every query for a given model receives certain constraints.
Logout from every devices except the currently logged in one in Laravel
May 5, 2019
Every robust web app has this feature where you’re provided with a setting through which you can choose to logout from all the devices you’ve been logged in from previously, except the current one. This is certainly a nice security feature that you can provide to your user without them even asking for it and if your app is built on top of Laravel 5.6, this comes out-of-the-box.
Laravel Route Model Bindings - Implicit Vs. Explicit Binding
April 29, 2019
There’s this neat feature in Laravel where you can validate model IDs that have been injected into the route by injecting model instances directly at route level.
Attribute casting in Laravel Eloquent
April 15, 2019
Laravel’s Eloquent is without a doubt a great ORM exists right now. It has some of the features which makes it ahead of its competitions. One such feature the ORM provides is called “Attribute casting”.
JavaScript functions' implementation inspired by PHP and Laravel
March 29, 2019
A sometime ago I tried my hands on implementing some of the PHP’s native functions in native JavaScript. The result is quite interesting list of JavaScript functions you’ve never asked about.
Implement Invite-only registrations using Laravel's signed URLs
March 28, 2019
There comes a time when you want URLs which are public but still you want some kind of authentication onto the same. For instance, you’d want such kind of URLs to enable invite-only registrations for your applications, where you’d send a URL to the user which that specific person only can access and register. In such scenarios, signed URLs can come in handy which are the special kind of URLs that have a “signature” hash appended to the query string to verify that the URL has not been modified since it was created.
Fetching dynamic attributes for models on-the-fly in Laravel
March 26, 2019
There exist this neat feature in Laravel using which you can add attributes in the models that do not have a respective column in your database.
Packages to make your Laravel development experience awesome.
February 9, 2019
While developing applications(not necessarily with Laravel), you come across the situation where you need to implement certain functionality. In such cases you shouldn’t want to reinvent the wheel if the functionality is been implemented by someone as a package, accepted well by the community and is ready to be consumed. It’s a no-brainer. I use to follow the same approach and today in this article, I’m going to list out some of my favorite Laravel packages which have made my experience with development in Laravel delicious.
Build your own Laravel artisan commands for your project
January 9, 2019
When working on a project, there comes a time when you need to automate certain tasks. In such cases, it is better to use a CLI tool which can be run from the command prompt because using a web APIs for certain tasks is cumbersome.
Why you should use Laravel Queues
December 21, 2018
There comes times when you wouldn’t want your end users staring at white screens or that intimidating loaders for a long time. For instance when user registers to your site, you must have configured your website to send a welcome email or a confirmation email upon registering. So, that operation should be snappy and for that purpose you’d actually want to reduce the amount of time your app takes while sending the email to the user. Laravel Queues comes to the recue for achieving such kind of time consuming tasks.
Laravel - Accessors & Mutators
August 23, 2017
Accessors and mutators allow you to format Eloquent attribute values when you retrieve or set them on model instances. I’ll explain how you can you use them into your app.
Laravel Eager Loading - load() Vs. with()
August 17, 2017
Today, while working with one of my projects(which is built on top Laravel) I bumped into the situation where I needed to get associated model’s data for one of the models. So here, I had two approaches in Laravel to accomplish this which are basically called Eager Loading: