D
D
D44k2015-04-29 23:32:08
Laravel
D44k, 2015-04-29 23:32:08

How to change table in Laravel?

Sorry noob.
There is a Goods model class in which a selection is made from the database:

$best_sellers = Goods::select('name','price','img')
        								->orderBy('popular', 'desc')
        								->take('8')
        								->get();

All OK. The selection comes from the goods table. matches the class name.
I need to make a selection from another table in the same model class:
$main_news = Goods::table('news')
        								->select('date','title','body','img')
        								->orderBy('date', 'desc')
        								->take('4')
        								->get();

Swears at an unknown table() method:
Call to undefined method Illuminate\Database\Query\Builder::table()

How to choose which table to select from. Why not create a new class of the same name for each table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2015-04-29
@D44k

Exactly what to create. One table - one model. Or, if you like, one model - one table :)
Or use QueryBuilder right away if you only have selections of some fields and which should not be converted into models

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question