2022-11-27 02:34:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\Application;
|
2022-12-27 16:25:22 +00:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2022-11-27 02:34:36 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class ApplicationController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function index(): View
|
2022-11-27 02:34:36 +00:00
|
|
|
{
|
2023-01-10 13:42:27 +00:00
|
|
|
$applications = (new Application)->paginate(100);
|
2022-11-27 02:34:36 +00:00
|
|
|
|
|
|
|
return view('admin.applications.index', compact('applications'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
2023-02-07 09:04:11 +00:00
|
|
|
* @param Request $request
|
2022-11-27 02:34:36 +00:00
|
|
|
* @return View
|
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function store(Request $request): View
|
2022-11-27 02:34:36 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
|
|
|
|
$this->validate($request, [
|
|
|
|
'name' => 'required',
|
|
|
|
'description' => 'required',
|
|
|
|
'api_token' => 'required|unique:applications,api_token',
|
|
|
|
]);
|
|
|
|
|
2023-01-10 13:42:27 +00:00
|
|
|
$application = (new Application)->create($request->all());
|
2022-11-27 02:34:36 +00:00
|
|
|
|
|
|
|
return view('admin.applications.edit', compact('application'));
|
|
|
|
}
|
|
|
|
|
2022-12-27 16:25:22 +00:00
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return View
|
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function create(): View
|
2022-12-27 16:25:22 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
|
|
|
|
return view('admin.applications.create');
|
|
|
|
}
|
|
|
|
|
2022-11-27 02:34:36 +00:00
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
2023-02-07 09:04:11 +00:00
|
|
|
* @param Application $application
|
2022-12-27 16:25:22 +00:00
|
|
|
* @return RedirectResponse
|
2022-11-27 02:34:36 +00:00
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function show(Application $application): RedirectResponse
|
2022-11-27 02:34:36 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
|
|
|
|
return redirect()->route('admin.applications.edit', $application);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
2023-02-07 09:04:11 +00:00
|
|
|
* @param Application $application
|
2022-11-27 02:34:36 +00:00
|
|
|
* @return View
|
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function edit(Application $application): View
|
2022-11-27 02:34:36 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
|
|
|
|
return view('admin.applications.edit', compact('application'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
2023-02-07 09:04:11 +00:00
|
|
|
* @param Request $request
|
|
|
|
* @param Application $application
|
2022-12-27 16:25:22 +00:00
|
|
|
* @return RedirectResponse
|
2022-11-27 02:34:36 +00:00
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function update(Request $request, Application $application): RedirectResponse
|
2022-11-27 02:34:36 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
|
|
|
|
$this->validate($request, [
|
|
|
|
'name' => 'required',
|
|
|
|
'description' => 'required',
|
2023-02-07 09:04:11 +00:00
|
|
|
'api_token' => 'required|unique:applications,api_token,'.$application->id,
|
2022-11-27 02:34:36 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$application->update($request->all());
|
|
|
|
|
|
|
|
return back()->with('success', '应用程序已更新。');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
2023-02-07 09:04:11 +00:00
|
|
|
* @param Application $application
|
2022-12-27 16:25:22 +00:00
|
|
|
* @return RedirectResponse
|
2022-11-27 02:34:36 +00:00
|
|
|
*/
|
2023-01-10 13:42:27 +00:00
|
|
|
public function destroy(Application $application): RedirectResponse
|
2022-11-27 02:34:36 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
|
|
|
|
$application->delete();
|
|
|
|
|
|
|
|
return redirect()->route('admin.applications.index')->with('success', '应用程序已删除。');
|
|
|
|
}
|
|
|
|
}
|