There are many ways to “reset” an object’s value in JavaScript. In this article, I will show you my approach to this case.
1. Default Object (not elegant)
let item = {
discount : true,
percentage : false,
qty : true,
unit_price …

Wouldn’t it be cool if there was a history of the model in our project?
Yes of course! You only need to add the HasHistory
Trait and the HasHistoryInterface
Interface to the choosen model.
You will receive the history of actions performed on a given model in an easily accessible way:
- created
- updated
- deleted
- restored
A user is assigned to each action, if logged in. This means that you can receive full information that a specific user has performed on tracked models.
The exact installation is in the repository.
When creating an API, it is sometimes necessary to know if our code is not doing any unnecessary SQL queries.
These few lines of code allow queries to be written to the /storage/logs/query.log
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use Illuminate\Database\Events\QueryExecuted;
private function queryListener(): void
{
DB::listen(function (QueryExecuted $q) {…
Quick Trick to anyone who had the same dilemma as me.
How to get value from collection with one-to-many relationship ?
The solution is really simple. Use Dot notation !
Post::with('users:id')->get()->pluck('users.*.id')->collapse();
Simple and elegant.