We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Jsonable
castAsJson()
1 parent 03e1373 commit 58dc491Copy full SHA for 58dc491
src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php
@@ -2,6 +2,7 @@
2
3
namespace Illuminate\Foundation\Testing\Concerns;
4
5
+use Illuminate\Contracts\Support\Jsonable;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
use Illuminate\Support\Arr;
@@ -127,7 +128,11 @@ protected function isSoftDeletableModel($model)
127
128
*/
129
public function castAsJson($value)
130
{
- $value = is_array($value) ? json_encode($value) : $value;
131
+ if ($value instanceof Jsonable) {
132
+ $value = $value->toJson();
133
+ } elseif (is_array($value)) {
134
+ $value = json_encode($value);
135
+ }
136
137
return DB::raw("CAST('$value' AS JSON)");
138
}
0 commit comments