What is Accessors And Mutators in Laravel 9?

Sometimes need to modify a field value while retrieving records using Laravel Eloquent e.g. get date from datetime field, make field value in upper case, etc.

To do that you can either use selectRaw() or Accessors.

Similarly, If you want to update the value while inserting or updating using Eloquent then you can either modify value every time before storing or use Mutators.

In this tutorial, I show how you can use Accessors And Mutators in the Laravel 9 project.

What is Accessors And Mutators in Laravel?

Read more

Add CSV Excel PDF Export buttons in Yajra DataTables – Laravel

DataTables allows to export data in multiple formats like – CSV, Excel, and Pdf. This is not by default enabled.

Required including some more libraries to start using it.

In this tutorial, I show how you can add export buttons in Yajra DataTable in Laravel 9.

I am assuming you have already installed and set up the Yajra DataTable package if not then you can view this tutorial.

Add CSV Excel PDF Export buttons in Yajra DataTables - Laravel

Read more

Make Reusable queries using Query Scope in Laravel

In Laravel with the use of scope in Model, you can save time of writing the same script in multiple places in your project.

For example, selecting records based on their status – active/inactive/suspended.

The query scope methods are prefixed by scope.

In this tutorial, I show how you can create a reusable query using Query scope in Laravel 9.

Make Reusable queries using Query Scope in Laravel

Read more