snetty / laravel-calculated-columns
Create calculated columns for laravel models
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/snetty/laravel-calculated-columns
Requires
- illuminate/database: >=5.1.0
This package is not auto-updated.
Last update: 2025-10-25 23:42:54 UTC
README
An simple way to add calculated columns to your eloquent models
Usage
composer require snetty/laravel-calculated-columns- add the trait
Snetty\LaravelCalculatedColumns\CalculatedColumns;to your models - declare your calculated columns in the form
protected $calculated_columns = ['new_column_name' => '(SELECT "SOME SUB QUERY")']; - You can use
:user_idin your subqueries and it will be parsed in automatically. If no user is present, the whole subquery will return false - you can now treat the column in eloquent as if it were a physical column