added export functionality

This commit is contained in:
Ritikesh yadav
2024-05-14 17:27:34 +05:30
parent 0ef79971d0
commit cab2d50f69
5 changed files with 66 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\Admin;
use App\Exports\UserProductExport;
use App\Models\User;
use Illuminate\Http\Request;
use App\Models\MonthlyUpdateMaster;
@@ -39,6 +40,33 @@ class ManageUserProductController extends Controller
return view('Admin.Pages.manage_investors.manage_user_product.manage_user', compact('userProduct'));
}
public function exportUserProduct()
{
// dd('hello');
$data = MonthlyUpdateMaster::with(
['investor' => function($query){
$query->select('id','name');
// },'products.categorys' => function($query){
// $query->select('id','categories_id');
// }])->select('id','users_id','products_id','custom_id')->get();
},'products.categorys'])->get();
// dd($data->toArray());
$withClearData = collect();
$new = [];
$data->each(function($value) use($withClearData, $new){
$new['user_name'] = $value->investor->name;
$new['custom_id'] = $value->custom_id;
$new['investor_name'] = $value->investor->name;
$new['category'] = $value->products->categorys->category_name;
$new['holding_status'] = $value->holding_status;
$new['created_at'] = $value->created_at->format('d-m-Y');
$withClearData->push($new);
});
$columns = ['User Name', 'CustomId', 'Investor Name', 'Category', 'Holding Status', 'Created At'];
// dd($withClearData->sortByDesc('created_at'));
return Excel::download(new UserProductExport($withClearData->sortByDesc('created_at'), $columns), 'UsersProduct.XLSX');
}
public function redeemWithSoldAmount(Request $request)
{
// dd($request->all());