codewiser / dadata
Plug DaData into laravel
v1.1.6
2024-08-27 15:03 UTC
Requires
- php: ^8.1
- hflabs/dadata: ^22.3
- laravel/framework: ^10.0|^11.0
Requires (Dev)
- phpunit/phpunit: ^10.3
README
Laravel package.
Brings DaData
data types.
For now supported search for taxpayers only.
Add to config/services.php
:
'dadata' => [ 'token' => env('DADATA_TOKEN'), 'secret' => env('DADATA_SECRET'), ]
Usage
Taxpayer attribute
You may store taxpayer
object in a model attribute.
use Codewiser\Dadata\Taxpayer\Casts\AsTaxpayer; use Codewiser\Dadata\Taxpayer\Taxpayer; use Illuminate\Database\Eloquent\Model; /** * @property integer $id * @property null|Taxpayer $taxpayer */ class Organization extends Model { protected $casts = [ 'taxpayer' => AsTaxpayer::class, ]; }
Search for taxpayer
Inject dependency TaxpayerServiceContract
wherever you need:
use Codewiser\Dadata\Taxpayer\Contracts\TaxpayerServiceContract; use Illuminate\Http\Request; public function index(Request $request, TaxpayerServiceContract $taxpayers) { $taxpayer = $taxpayers->search($request->input('inn'))->first(); // .... $organization->taxpayer = $taxpayer; $organization->save(); }