Stack Overflow Asked by Maqsud Inamdar on December 9, 2021
I’m trying to write function which will get all filename
for particular job_id
.
DATABASE: analytics_report
| id | job_id | filename |
|----|--------|----------|
| 1 | abcd | file1 |
| 2 | abcd | file2 |
| 3 | bcde | file3 |
CONTROLLER:
public function downloadZip(Request $request)
{
@$job_id = $request->job_id;
$filename = array();
}
Example:
If user selects job_id
= abcd then filename
variable in controller should have an array of files from Database.
Thanks!
You could use the DB class to do this:
public function downloadZip(Request $request)
{
$job_id = $request->job_id;
$filenames = DB::table('analytics_report')->select('filename')
->where('job_id', $job_id)->get()->toArray();
}
Alternatively, if you already have a model for the analytics_report and assuming your model is AnalyticsReport
, you could that with:
public function downloadZip(Request $request)
{
$job_id = $request->job_id;
$filenames = AnalyticsReport::select('filename')
->where('job_id', $job_id)->toArray();
}
Answered by Clement Sam on December 9, 2021
In namespace
use DB;
in download method:
public function downloadZip(Request $request)
{
$job_id = $request->job_id;
$filenames = DB::table('analytics_report')->where('job_id',$job_id)->pluck('filename');
}
Answered by Songoudaha Gabeta Soro on December 9, 2021
Use This Query
public function downloadZip(Request $request)
{
$job_id = $request->job_id;
$file = DB::table('table_name')->where('job_id','=',$job_id)->select('filename')->get()->toArray();
}
Answered by xXx_HAWK on December 9, 2021
In namespace add
use DB;
then in method add table name,
public function downloadZip(Request $request)
{
$job_id = $request->job_id;
$filename = DB::table('table_name')->where('job_id',$job_id)->get()->pluck('filename')->toArray();
}
Answered by Alok p on December 9, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP