-1

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);
}
Mohammad Hosseini
  • 1,649
  • 1
  • 16
  • 31
digi soft
  • 37
  • 5
  • and what is the problem? `$categories` is never going to be equal to `null`, it is always a Collection object ... if you are getting an error check your logs so you know what the error is – lagbox Dec 09 '19 at 10:32
  • What do you mean of (get from database before function)? before which function? more explain about your problem, please! – Mohammad Hosseini Dec 09 '19 at 10:38
  • muhammad Hossein please check images link – digi soft Dec 09 '19 at 12:14

1 Answers1

0

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){

}
Patryk
  • 75
  • 4
  • i wanna first record ->where('business_id', '=', '$business_id') use but still same error check out this images please https://imgur.com/HC7v2Sp https://imgur.com/N2WhDNA – digi soft Dec 09 '19 at 12:11
  • Check logs.The logs are located in storage directory. – Patryk Dec 09 '19 at 12:16
  • well what you think i paste your code in my project on right place or not – digi soft Dec 09 '19 at 12:21
  • this error is showing in log [2019-12-09 17:53:43] live.ERROR: Class 'Modules\Superadmin\Http\Controllers\subscriptions' not found {"userId":299,"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Class 'Modules\\Superadmin\\Http\\Controllers\\subscriptions' not found at C:\\xampp\\htdocs\\UltimatePOS\\Modules\\Superadmin\\Http\\Controllers\\BaseController.php:18) – digi soft Dec 09 '19 at 12:28
  • Sory my bad i looked on wrong image,your function _add_subscription don't have arg like $categories ,if you wanna get first record basic on arg in _add_subscription,you should use that code inside that function ```$categories = subscriptions::select('start_date', 'end_date')->where('business_id', '=', $business_id)->first();``` but change '$business_id' to $business_id if you wanna use quotation marks use " " – Patryk Dec 09 '19 at 12:35
  • finally i got the solution with this code $data = \DB::table("subscriptions") ->select("subscriptions.*", \DB::raw("(SELECT subscriptions.start_date FROM subscriptions WHERE subscriptions.business_id = $business_id ) as date")) ->orderBy('subscriptions.start_date', 'desc') ->get(); dd($data); but still i want help of you that i dont get exact data that i want it's showing blank image https://imgur.com/eCrGeTW – digi soft Dec 10 '19 at 08:36
  • Ok ,can you edit your post and put there result from dd($data) ? – Patryk Dec 10 '19 at 08:38
  • https://stackoverflow.com/questions/59263194/i-got-the-blank-value-from-db-in-laravel-on-select – digi soft Dec 10 '19 at 08:43