Skip to content

Some sugar

Alex Morozov edited this page Oct 21, 2020 · 3 revisions

Why is this needed?

Just so as not to write too much 😤

Usage

like

// select * from `invoices` where `name` like '%foo%'
Invoice::like('name', 'foo')->get();
// select * from `invoices` where `name` like '%foo'
Invoice::likeLeft('name', 'foo')->get();
// select * from `invoices` where `name` like 'foo%'
Invoice::likeRight('name', 'foo')->get();

casting

Imagine that you have a field in the database in the format of a string, and you need to sort by it like number. Of course you will cast it.
Some types for exaple date, datetime, time, char, signed, unsigned, binary.

Invoice::castColumn('name', 'signed')->orderBy('name')->get();

or multiple

Invoice::castColumn(['name' => 'signed', 'name2' => 'signed'])->orderBy('name')->get();
Clone this wiki locally