Answer the question
In order to leave comments, you need to log in
How to access a specific table through a model in laravel 7?
Model - Shop.php
Controller - ShopController.php
Shop.php
class Shop extends Model
{
protected $table='product';
protected $connection = 'sqlsrv2';
}
use App\Shop;
use DB;
class AdminPanelController extends Controller
{
public function adminshop() {
//return view("admin", ['item' => Shop::all()->toArray()]);
DB::connection('sqlsrv2')->table('product')->get()->toArray();
}
}
Answer the question
In order to leave comments, you need to log in
The model is not a universal facade for accessing the database, the "one model - one table" approach is correct in most cases, if different tables are connected by one-to-one, one-to-many, many-to-many relationships, then for this laravel also has tools to get related data
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question