Latest Blogs

Learn about my progress!

Accessors and Mutators in Laravel

Defining An Accessor To define an accessor, create a getFooAttribute method on your model where Foo is the "studly" cased name of the column you wish to access. In this example, we'll define an accessor for the first_name attribute. The accessor will automatically be called by Eloquent when attempting to retrieve the value of the first_name attribute: <?php namespace Ap...

Multiple Inheritance in PHP

Multiple Inheritance is a feature of Object Oriented Programming which inherits features from more than one object or class. We use Interfaces to implement them in more than one class.  interface I1 { public function fun1(); public function fun2(); } interface I2 { public function fun3(); public function fun4(); } class A { public function fun1(){ //do s...

Stripe Integration in Laravel

Stripe is a US technology company, operating in over 25 countries, that allows both private individuals and businesses to accept payments over the Internet. For integrating Stripe in Laravel, first add the Cashier package for Stripe to your composer.json file and run the composer update command: "laravel/cashier": "~7.0" Next, register the&nb...

Using Events on Laravel Eloquent

Eloquent models fire several events, allowing you to hook into the following points in a model's lifecycle: creating, created, updating, updated, saving, saved, deleting, deleted, restoring, restored. Events allow you to easily execute code each time a specific model class is saved or updated in the database. Whenever a new model is saved for the first time, the creating, created events wil...

Eager Loading in Laravel

When accessing Eloquent relationships as properties, the relationship data is "lazy loaded". This means the relationship data is not actually loaded until you first access the property. However, Eloquent can "eager load" relationships at the time you query the parent model. Eager loading alleviates the N + 1 query problem. To illustrate the N + 1 query problem, consider a Book ...

Collations in MySQL and Laravel Database Settings

A collation is a set of rules that defines how to compare and sort character strings. Each collation in MySQL belongs to a single character set. Every character set has at least one collation, and most have two or more collations. A collation orders characters based on weights. Each character in a character set maps to a weight. Characters with equal weights compare as equal, and characters wit...

Password Broker in Laravel

Password Broker: Password Broker in laravel is used to reset forgotten password for users. PasswordBroker class will create a token for user and send an email for the set new password link, where user can set a new password. To reset password make PasswordsController and a form which will submit your email. It will point to your store() in PasswordsController which will have code...

Making Image Uploading Trait in Laravel

For uploading image in laravel we can simply make a trait and use it in any model and do the image upload. We can also do validations on the image which is explained in http://blog.samarthasinha.com/blog/making-validation-trait-laravel and http://blog.samarthasinha.com/blog/using-events-laravel-eloquent link. The code for image validation is below: <?php namespace App\Traits; ...

Components in Angular2

Components are a logical piece of code for Angular JS application. A Component consists of the following − Template − This is used to render the view for the application. This contains the HTML that needs to be rendered in the application. This part also includes the binding and directives. Class − This is like a class defined in any language such as C....

Abstract Classes and Interfaces

Abstract Classes An abstract class is a class that is declared abstract—it may or may not include abstract methods. You cannot create an object of an abstract class. They can only be inherited and by another class. An abstract method is a method that is declared but not defined, like this: abstract function xyz(); If you want to create an abstract function you have to declare that cl...