Support the ongoing development of Laravel.io →
posted 9 years ago
Database
Last updated 2 years ago.
0

Or even easier example,

Model::addSelect('COUNT(*) as total')->get();

0

You should use accessors to create calculated attributes on your model: http://laravel.com/docs/4.2/eloquent#accessors-and-mutators

0

You need to use the "raw" method on the DB facade.

use DB;

Model::select(DB::raw("IF(premium > 0, 'yes', 'no') as PremiumYesNo"))->get();

Model::addSelect(DB::raw('COUNT(*) as total'))->get();

Those should work for you.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

filip01 filip01 Joined 2 Jan 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.