update hosting
This commit is contained in:
@@ -11,12 +11,14 @@ use App\Http\Requests\ModuleHosting\CreateHostingRequest;
|
||||
use App\Http\Requests\ModuleHosting\UpdateHostingRequest;
|
||||
use App\Repositories\Module\HostingServer\HostingServerRepositoryInterface;
|
||||
use Exception;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
|
||||
class ModuleHostingController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
public HostingServerRepositoryInterface $hostingServerRepository
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
// show all hosting module
|
||||
public function index(Request $request)
|
||||
{
|
||||
@@ -30,7 +32,7 @@ class ModuleHostingController extends Controller
|
||||
}
|
||||
public function import(Request $request)
|
||||
{
|
||||
if (! $request->file) {
|
||||
if (!$request->file) {
|
||||
return back()->withErrors("Please choose your file");
|
||||
}
|
||||
$data = Excel::toArray([], $request->file);
|
||||
@@ -48,7 +50,7 @@ class ModuleHostingController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
if (! isset($allData) || (isset($allData) && count($allData) < 1)) {
|
||||
if (!isset($allData) || (isset($allData) && count($allData) < 1)) {
|
||||
return back()->withErrors('No data imported');
|
||||
}
|
||||
DB::beginTransaction();
|
||||
@@ -77,7 +79,7 @@ class ModuleHostingController extends Controller
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$data = $request->all();
|
||||
$data['password'] = SignRSA::EncryptFunc($request->password);
|
||||
$data['password'] = SignRSA::EncryptFunc($request->password);
|
||||
$this->hostingServerRepository->create($data);
|
||||
DB::commit();
|
||||
} catch (\Exception $error) {
|
||||
@@ -90,14 +92,15 @@ class ModuleHostingController extends Controller
|
||||
{
|
||||
|
||||
$server = $this->hostingServerRepository->find($id);
|
||||
if (! $server) return back()->withErrors('Can\'t find server by id ' . $id);
|
||||
if (!$server)
|
||||
return back()->withErrors('Can\'t find server by id ' . $id);
|
||||
$title = 'View server hosting information';
|
||||
return view('administrator.pages.module.hosting.edit', compact('title', 'server'));
|
||||
}
|
||||
public function update(UpdateHostingRequest $request, int $id = 0)
|
||||
{
|
||||
$server = $this->hostingServerRepository->find($id);
|
||||
if (! $server) {
|
||||
if (!$server) {
|
||||
return back()->withErrors('Invalid Request');
|
||||
}
|
||||
$request->validated();
|
||||
@@ -110,8 +113,8 @@ class ModuleHostingController extends Controller
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$data = $request->all();
|
||||
if (! empty($request->get('password'))) {
|
||||
$data['password'] = SignRSA::EncryptFunc($request->password);
|
||||
if (!empty($request->get('password'))) {
|
||||
$data['password'] = SignRSA::EncryptFunc($request->password);
|
||||
}
|
||||
$this->hostingServerRepository->update($id, $data);
|
||||
DB::commit();
|
||||
@@ -124,7 +127,7 @@ class ModuleHostingController extends Controller
|
||||
public function destroy(int $id = 0)
|
||||
{
|
||||
$server = $this->hostingServerRepository->find($id);
|
||||
if (! $server) {
|
||||
if (!$server) {
|
||||
return back()->withErrors('Invalid Request');
|
||||
}
|
||||
DB::beginTransaction();
|
||||
@@ -138,4 +141,30 @@ class ModuleHostingController extends Controller
|
||||
}
|
||||
return redirect()->route('module.hosting.index')->with('success', 'Deleted successfully.');
|
||||
}
|
||||
|
||||
public function datatable(Request $request)
|
||||
{
|
||||
$query = $this->hostingServerRepository->filter(
|
||||
$request->all(),
|
||||
[],
|
||||
[],
|
||||
['*'],
|
||||
true
|
||||
);
|
||||
|
||||
return DataTables::eloquent($query)
|
||||
->addColumn(
|
||||
'action',
|
||||
function ($d) {
|
||||
return view('administrator.pages.module.dns.datatable.action', ['row' => $d])->render();
|
||||
}
|
||||
)
|
||||
->filterColumn('name', function ($query, $keyword) {
|
||||
$query->where('name', 'like', "%{$keyword}%");
|
||||
})
|
||||
->filterColumn('user', function ($query, $keyword) {
|
||||
$query->where('user', 'like', "%{$keyword}%");
|
||||
})
|
||||
->make(true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user