0

I'm new to Laravel. Can anyone please let me know how to use "AS" operator for table 'products' in below SQL query?

$obj = new Product();
$main_data = $obj
->select('products.*','t2.title')
->leftJoin('category as t2', 't2.id', '=', 'products.subcategory_id')
->where('products.status',1); 
  • Option 1: use `from()` to redefine the `from` part of the query: `$obj = Product::query()->from('products', 'p')->select('p.*', 't2.title')->leftJoin('category as t2', 't2.id', 'p.subcategory_id')->where('p.status', 1)` – IGP Jan 14 '22 at 17:29
  • Option 2 (I'm not sure if this one works!): Go to your `Product` model, and define it in the `table` property. `protected $table = 'products as p';` – IGP Jan 14 '22 at 17:31

0 Answers0