2022-11-18 09:16:30 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2022-11-18 10:50:28 +00:00
|
|
|
use App\Models\Host;
|
2022-11-19 02:11:56 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2022-11-18 09:16:30 +00:00
|
|
|
use Illuminate\Http\Request;
|
2022-11-18 11:39:30 +00:00
|
|
|
use Illuminate\View\View;
|
2022-11-18 09:16:30 +00:00
|
|
|
|
|
|
|
class HostController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
*
|
2022-12-18 10:08:46 +00:00
|
|
|
* @param Request $request
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @return View
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-12-18 10:08:46 +00:00
|
|
|
public function index(Request $request): View
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
2022-12-18 10:08:46 +00:00
|
|
|
$hosts = Host::with('user');
|
|
|
|
|
|
|
|
// 遍历所有的搜索条件
|
|
|
|
foreach (['name', 'module_id', 'status', 'user_id'] as $field) {
|
|
|
|
if ($request->has($field)) {
|
|
|
|
$hosts->where($field, 'like', '%' . $request->input($field) . '%');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-18 10:11:06 +00:00
|
|
|
$hosts = $hosts->paginate(100)->withQueryString();;
|
2022-11-18 09:16:30 +00:00
|
|
|
|
2022-11-18 10:50:28 +00:00
|
|
|
return view('admin.hosts.index', compact('hosts'));
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @param Host $host
|
2022-11-19 04:38:26 +00:00
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @return View
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-18 11:39:30 +00:00
|
|
|
public function edit(Host $host): View
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
|
|
|
//
|
2022-11-18 11:39:30 +00:00
|
|
|
|
|
|
|
return view('admin.hosts.edit', compact('host'));
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @param Host $host
|
2022-11-19 02:11:56 +00:00
|
|
|
*
|
|
|
|
* @return RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-19 02:11:56 +00:00
|
|
|
public function update(Request $request, Host $host): RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
|
|
|
//
|
2022-11-18 11:39:30 +00:00
|
|
|
|
|
|
|
$request->validate([
|
2022-11-19 02:11:56 +00:00
|
|
|
// 'name' => 'required|string|max:255',
|
2022-11-18 11:39:30 +00:00
|
|
|
'managed_price' => 'nullable|numeric',
|
|
|
|
]);
|
|
|
|
|
2022-11-19 02:11:56 +00:00
|
|
|
$req = $request->only('managed_price');
|
|
|
|
|
|
|
|
$host->update($req);
|
2022-11-18 11:39:30 +00:00
|
|
|
|
|
|
|
return back()->with('success', '此主机已更新。');
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2022-11-19 06:04:42 +00:00
|
|
|
* @param Host $host
|
2022-11-19 02:11:56 +00:00
|
|
|
*
|
|
|
|
* @return RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
*/
|
2022-11-19 02:11:56 +00:00
|
|
|
public function destroy(Host $host): RedirectResponse
|
2022-11-18 09:16:30 +00:00
|
|
|
{
|
2022-11-19 02:11:56 +00:00
|
|
|
$host->safeDelete();
|
|
|
|
|
|
|
|
return redirect()->route('admin.hosts.index')->with('success', '正在排队删除此主机。');
|
2022-11-18 09:16:30 +00:00
|
|
|
}
|
|
|
|
}
|