A
A
amk2016-11-09 19:30:53
Laravel
amk, 2016-11-09 19:30:53

How to add table name to hasMany in laravel5?

There are 2 classes. How to make a query to a specific table from one? without creating yet another class or file for the requested table. Is it possible to dynamically define a table in hasMany?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dskozin, 2016-11-17
@dskozin

Using QueryBuilder apparently.
$users = DB::table('users')->get();
https://laravel.com/docs/5.3/queries
It's probably better to expand the task with specific examples, otherwise it's hard to abstract like that.
It's generally possible to write a boot() in a model that (the content of the boot) will be executed before the rest of the model's code is loaded, but that will be done before the routes are processed, so it's not entirely clear how to pass the second link. And again, it is not clear - why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question