api code global jain
This commit is contained in:
87
app/Repositories/Backend/Sangh/SanghService.php
Normal file
87
app/Repositories/Backend/Sangh/SanghService.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Backend\Sangh;
|
||||
|
||||
use App\Models\Sangh;
|
||||
use Exception;
|
||||
use App\Services\BaseService;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class SanghService extends BaseService
|
||||
{
|
||||
protected const MODEL = Sangh::class;
|
||||
|
||||
public function prepareSearchQuery($request)
|
||||
{
|
||||
$searchQuery = [];
|
||||
|
||||
try {
|
||||
$searchQuery = $this->query()->with('dharma','sampraday');
|
||||
$columns = ['id','name', 'sangh_type', 'dharma_id', 'sampraday_id','mobile_number', 'status'];
|
||||
|
||||
if (isset($request['name']) && $request['name'] != '') {
|
||||
$searchQuery = $searchQuery->where('name', 'like', '%' . $request['name'] . '%');
|
||||
}
|
||||
|
||||
if (isset($request['order']) && $request['order'] != "") {
|
||||
$searchQuery = $searchQuery->orderBy(
|
||||
$columns[$request['order'][0]['column']],
|
||||
$request['order'][0]['dir']
|
||||
);
|
||||
}
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return $searchQuery;
|
||||
}
|
||||
|
||||
public function getListing($request)
|
||||
{
|
||||
$response = (object)[];
|
||||
|
||||
try {
|
||||
$dataTableQuery = $this->prepareSearchQuery($request);
|
||||
|
||||
$response = Datatables::of($dataTableQuery)
|
||||
->addColumn(
|
||||
'checkbox_action',
|
||||
function ($sangh) {
|
||||
return $sangh->sangh_checkbox_action;
|
||||
}
|
||||
)
|
||||
->addColumn('sangh_type', function ($sangh) {
|
||||
return config('common-variables.sangh_types_label')[$sangh->sangh_type] ?? '-';
|
||||
})
|
||||
->addColumn('dharma',function($sangh){
|
||||
return $sangh?->dharma?->name ?? '-';
|
||||
})
|
||||
->editColumn('mobile_number', function ($sangh) {
|
||||
return $sangh?->mobile_number ?? '-';
|
||||
})
|
||||
->addColumn('sampraday',function($sangh){
|
||||
return $sangh?->sampraday?->name ?? '-';
|
||||
})
|
||||
->addIndexColumn()
|
||||
->addColumn(
|
||||
'status',
|
||||
function ($sangh) {
|
||||
return $sangh->sangh_status_label;
|
||||
}
|
||||
)
|
||||
->addColumn(
|
||||
'action',
|
||||
function ($sangh) {
|
||||
return $sangh->action_buttons;
|
||||
}
|
||||
)->rawColumns(['status','action', 'checkbox_action'])
|
||||
->make(true);
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user