Victor Alfonso's avatar

How use both models with same name in laravel

Hi i using this package to get all the data from a ecommerce with woocomerce

https://github.com/Codexshaper/laravel-woocommerce

and i would like to use this on my Products controller to get the products from woocomerce and if doesnt exist create the products, but i got this error because i have already a model called "Product" on my laravel system. This secction is from the part when you call all the models that you want to use

use App\Supplier;
use App\Product;
use Codexshaper\WooCommerce\Facades\Product;

and obiusly i got the error: Cannot use App\Product as Product because the name is already in use how can i use both?? i need to use both because i do others eloquent querys with the main product model from laravel

0 likes
3 replies
Braunson's avatar
Braunson
Best Answer
Level 18

You can alias them.. e.g.

use App\Supplier;
use App\Product;
use Codexshaper\WooCommerce\Facades\Product as WCProduct;

Then you'd use WCProduct or whatever you want to call it when you need to call it.

1 like
michaelkampmann's avatar

Exactly as Braunson said, then just initialize like this.

$woocommerceProduct = new WCProduct();
$myProduct = new Product();

Please or to participate in this conversation.