how to get data from mysql in laravel

200 Views Asked by At

Hello guys i am new on laravel and am currently working on laravel project i have got this project from someone all things are working perfectly but something i want to get from database and i dont know how can i do it i just want to get start_date and end_date from database before function please help me.Thanks. please see the situation https://i.stack.imgur.com/JFhhI.jpg

https://imgur.com/xWVvTm2

$categories = subscriptions::select('start_date', 'end_date')
                           ->where('business_id', '=', '$business_id')
                           ->get();
if($categories=="")
{
   $dbvalue['start_date'] = '';
   dd($dbvalue);
}
else{
   $gateways['start_date'] = '';
   dd($dbvalue);
}
1

There are 1 best solutions below

8
On

Hi if you wanna first record ->where('business_id', '=', '$business_id') use

$categories = subscriptions::select('start_date', 'end_date')
                       ->where('business_id', '=', '$business_id')
                       ->first();

and

$startDate=$categories->start_date
$endDate=$categories->end_date

but if you wanna get array use this

$categories = subscriptions::select('start_date', 'end_date')
                       ->where('business_id', '=', '$business_id')
                       ->get();

but you should sort this query then you can access to this data use foreach loop

foreach($categories as $cat){

}