Selecting two values from the same table but under different conditions?
// I want to get two record. One record has to be promoted and the other is not.
$students = Student::where('promoted', 1)
->where('promoted', 0) // what should I do here?
->take(2)
->get();
@tray2 thanks for your reply. In my case I want two record, where one has to be promoted and other is not.
where and orWhere checks either promoted or not promoted. So it doesn't ensure me that it will return one with promoted result and other with non promoted.
I think in this case you could use have some changes in your database structure and I think it would be very easy to execute what you were saying in your last comment; you could have a table name gift_names and another table name product_names and a mid table combine those things like product_gifts which has two column e.g. product_id,gift_id; then when you select the product, you could only show those gifts which were selected for that specific product like:
public function get_gifts_according_to_product(Request $request)
{$gifts = DB::table('product_gifts')
->join('product_names','product_gifts.product_id','=','product_names.id')
->join('gift_names','product_gifts.gift_id','=','gift_names.id')
->where('product_names.id',$request('product_id'))
->get();}