PHPackages                             remarkablemark/rector-laravel-database-expressions - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. remarkablemark/rector-laravel-database-expressions

ActiveLibrary[Database &amp; ORM](/categories/database)

remarkablemark/rector-laravel-database-expressions
==================================================

Rector to fix Laravel 10 database expressions

2.0.1(1y ago)0138MITPHPPHP &gt;=8.0CI passing

Since Dec 20Pushed 5mo agoCompare

[ Source](https://github.com/remarkablemark/rector-laravel-database-expressions)[ Packagist](https://packagist.org/packages/remarkablemark/rector-laravel-database-expressions)[ Fund](https://b.remarkabl.org/teespring)[ GitHub Sponsors](https://github.com/remarkablemark)[ RSS](/packages/remarkablemark-rector-laravel-database-expressions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (4)Versions (9)Used By (0)

rector-laravel-database-expressions
===================================

[](#rector-laravel-database-expressions)

[![packagist](https://camo.githubusercontent.com/90354053da36b2333cfbd189a08982dd4058667f2e522b2dbf268c7b50ea4cd8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656d61726b61626c656d61726b2f726563746f722d6c61726176656c2d64617461626173652d65787072657373696f6e73)](https://packagist.org/packages/remarkablemark/rector-laravel-database-expressions)[![test](https://github.com/remarkablemark/rector-laravel-database-expressions/actions/workflows/test.yml/badge.svg)](https://github.com/remarkablemark/rector-laravel-database-expressions/actions/workflows/test.yml)

[Rector](https://github.com/rectorphp/rector) to refactor Laravel 10 database expressions.

From [Laravel 10](https://laravel.com/docs/10.x/upgrade#database-expressions):

> Database "expressions" (typically generated via `DB::raw`) have been rewritten in Laravel 10.x to offer additional functionality in the future. Notably, the grammar's raw string value must now be retrieved via the expression's `getValue(Grammar $grammar)` method. Casting an expression to a string using `(string)` is no longer supported.
>
> If your application is manually casting database expressions to strings using `(string)` or invoking the `__toString` method on the expression directly, you should update your code to invoke the `getValue` method instead:
>
> ```
> use Illuminate\Support\Facades\DB;
>
> $expression = DB::raw('select 1');
>
> $string = $expression->getValue(DB::connection()->getQueryGrammar());
> ```

Requirements
------------

[](#requirements)

PHP &gt;=8.0

Install
-------

[](#install)

Install with [Composer](http://getcomposer.org/):

```
composer require --dev rector/rector remarkablemark/rector-laravel-database-expressions
```

Usage
-----

[](#usage)

Register rule in `rector.php`:

```
