Prettus mismatch when issuing invoice via Tinker ( Prettus/Repository/Eloquent/BaseRepository::__construct() must be an instance of Illuminate/Container/Container )



  • Hi All,
    Please, trying to find an example of interacting with bagisto using Tinker ?
    Say opening an order ... ?
    Thanks in advance for your time!
    best,
    s



  • For example ( I am actually trying to issue an invoice via tinker), as this:

    use Webkul\Sales\Repositories\OrderRepository; ( OK ! )

    $this_order = Webkul\Sales\Models\Order::where('id',262);
    => Illuminate\Database\Eloquent\Builder {#3862} ( OK ! )

    $a=new OrderItemRepository($this_order);
    TypeError: Argument 1 passed to Prettus/Repository/Eloquent/BaseRepository::__construct() must be an instance of Illuminate/Container/Container, instance of Illuminate/Database/Eloquent/Builder given on line 1

    My final goal is to reach the Invoice Controller method ( create/store ) to custom the invoice issuance flow ...

    any help appreciated !!
    thanks



  • Hi @nessuno,

    Please share all the commands which you have ran in tinker.



  • @devansh-webkul
    Thanks for your reply.
    I am trying to issue invoice based on order via tinker ( or via cli or post api ) ...
    Yes, the above commands were issued in Tinker as also per below:

    1. use Webkul\Sales\Repositories\OrderRepository;
      OK in Tinker
    2. $this_order = Webkul\Sales\Models\Order::where('id',262);
      OK in Tinker ( replies => Illuminate\Database\Eloquent\Builder {#3862} )
    3. But when I try to initiate the repository using:
      $a=new OrderItemRepository($this_order);
      then Tinker replies:
      TypeError: Argument 1 passed to Prettus/Repository/Eloquent/BaseRepository::__construct() must be an instance of Illuminate/Container/Container, instance of Illuminate/Database/Eloquent/Builder given on line 1

    But I can't iterate with the repository ...

    Thanks for your help, appreciated !
    s



  • Hi @nessuno,

    Did you go deeper? If you check the OrderItemRepository, you will see that this class is extends to Repository and further it is extend to BaseRepository.

    There you will see that, constructor is calling which needs an application instance. Because reflection API won't work there so you need to pass the application object manually.

    So just try this and let me know,

    $a = new OrderItemRepository(app(), $this_order);
    


  • @devansh-webkul
    I did go deeper, but your solution is better ...
    I ended up doing this:

    Route::get('custom_issue_invoice_by_order/{id}', '[email protected]_invoice')->defaults('_config', [
    'repository' => 'Webkul\Sales\Repositories\OrderRepository',
    'resource' => 'Webkul\API\Http\Resources\Sales\Order',
    'authorization_required' => true
    ]);

    ( Which works, [email protected]_invoice_by_order is a custom version of [email protected]; which essentially matches Interac / E-Transfers resulting in auto-payments without fees for the customers ... )

    But I like your solution better as with your way I might be able to get it via Tinker which is neat for interacting instead of APIing like I did ... Thanks @devansh-webkul you are a prince ! much appreciated.
    have a great day/night !
    s



  • Hi @nessuno,

    Thanks for the update.

    Also, if you like our support, you may give us the review here:- https://www.trustpilot.com/review/bagisto.com

    That would be grateful for us.

    Thanks & Regards,
    Devansh




Log in to reply