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 1My 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:- use Webkul\Sales\Repositories\OrderRepository;
OK in Tinker - $this_order = Webkul\Sales\Models\Order::where('id',262);
OK in Tinker ( replies => Illuminate\Database\Eloquent\Builder {#3862} ) - 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 - use Webkul\Sales\Repositories\OrderRepository;
-
Hi @nessuno,
Did you go deeper? If you check the
OrderItemRepository
, you will see that this class is extends toRepository
and further it is extend toBaseRepository
.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}', 'InvoiceController@issue_invoice')->defaults('_config', [
'repository' => 'Webkul\Sales\Repositories\OrderRepository',
'resource' => 'Webkul\API\Http\Resources\Sales\Order',
'authorization_required' => true
]);( Which works, InvoiceController@issue_invoice_by_order is a custom version of InvoiceController@store; 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 -
For sure, .. done https://www.trustpilot.com/reviews/5fb7aa3c5e693f08f004dfd9