gandaff's avatar

integrate InvoiceNinja with existing project

Hi, as InvoiceNinja got updated, and is working on latest Laravel 8.* I was wondering if there is a solution that I can integrate it with my existing project (VUE and backend API based manager).

With previous version of InvoiceNinja it was like impossible to be done, but time passed by, and maybe sb has already done such integration and can share a bit of his knowledge. Or maybe it can be done in other way, like to install fresh InvoiceNinja project and inject current project I am working on in it.

I'd appreciate any help/advice.

0 likes
1 reply
rodrigo.pedra's avatar

I answered a thread about integrating InvoiceNinja in a Laravel application 2 days ago:

https://laracasts.com/discuss/channels/laravel/how-to-use-a-non-laravel-php-package-in-a-laravel-application

But in summary InvoiceNinja SDK is distributed as a composer package, so you require it:

composer require invoiceninja/sdk-php

And use it as a normal class in your controllers:

<?php

use InvoiceNinja\Config as NinjaConfig;
use InvoiceNinja\Models\Client;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    NinjaConfig::setURL('https://ninja.dev/api/v1');
    NinjaConfig::setToken('Your InvoiceNinja API token');

     $client = Client::find(1);
     
     return $client;
});

In the thread linked above I talked with its OP around setting the token in only one place, but the SDK usage is basically done through InvoiceNinja SDK's classes.

Hope it helps.

2 likes

Please or to participate in this conversation.