Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
51 righe
1.3 KiB
51 righe
1.3 KiB
<?php |
|
|
|
namespace App\Providers; |
|
|
|
use Illuminate\Support\Collection; |
|
use Illuminate\Support\ServiceProvider; |
|
use function GuzzleHttp\json_decode; |
|
use function GuzzleHttp\json_encode; |
|
|
|
class MacroServiceProvider extends ServiceProvider |
|
{ |
|
/** |
|
* Register services. |
|
* |
|
* @return void |
|
*/ |
|
public function register() |
|
{ |
|
// |
|
} |
|
|
|
/** |
|
* Bootstrap services. |
|
* |
|
* @return void |
|
*/ |
|
public function boot() |
|
{ |
|
\Illuminate\Support\Collection::macro('recursive', function () { |
|
return $this->map(function ($value) { |
|
if (is_array($value) || is_object($value)) { |
|
return (new \Illuminate\Support\Collection($value))->recursive(); |
|
} |
|
return $value; |
|
}); |
|
}); |
|
|
|
\Illuminate\Support\Collection::macro('toObject', function () { |
|
return $this->map(function ($value) { |
|
if (is_array($value) || is_object($value)) { |
|
return (object) \json_decode(\json_encode($value)); |
|
} |
|
return $value; |
|
}); |
|
}); |
|
|
|
\Illuminate\Support\Collection::macro('object', function () { |
|
return \json_decode(\json_encode($this)); |
|
}); |
|
} |
|
}
|
|
|