Latest Blogs

Learn about my progress!

CSRF Protection in Laravel

Laravel makes it easy to protect your application from cross-site request forgery (CSRF) attacks. Cross-site request forgeries are a type of malicious exploit whereby unauthorized commands are performed on behalf of an authenticated user. Laravel automatically generates a CSRF "token" for each active user session managed by the application. This token is used to verify that ...

Resourceful Controllers in Laravel

Resource Controllers Laravel resource routing assigns the typical "CRUD" routes to a controller with a single line of code. For example, you may wish to create a controller that handles all HTTP requests for "photos" stored by your application. Using the make:controller Artisan command, we can quickly create such a controller: php artisan make:controller PhotoController...

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...

Inserting and Updating Related Models in Laravel

The Save Method Eloquent provides convenient methods for adding new models to relationships. For example, perhaps you need to insert a new Comment for a Post model. Instead of manually setting the post_id attribute on the Comment, you may insert the Comment directly from the relationship's save(): $comment = new App\Comment(['message' => 'A new comment.']); $post ...

Logging Request and Response with Controller and Function Name

Logging is one of the most powerful tools in software development. It gives you an idea of what your code is doing. In Laravel handling logs is very easy. When you start a new Laravel project, error and exception handling is already configured for you. The App\Exceptions\Handler class is where all exceptions triggered by your application are logged and then rendered back to the user. I have ...