Lae/app/Http/Controllers/Admin/ApplicationController.php

128 lines
2.7 KiB
PHP
Raw Normal View History

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
*/
public function index()
{
//
$applications = Application::paginate(100);
return view('admin.applications.index', compact('applications'));
}
/**
* Store a newly created resource in storage.
*
2022-12-27 16:25:22 +00:00
* @param Request $request
*
2022-11-27 02:34:36 +00:00
* @return View
*/
public function store(Request $request)
{
//
$this->validate($request, [
'name' => 'required',
'description' => 'required',
'api_token' => 'required|unique:applications,api_token',
]);
$application = Application::create($request->all());
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
*/
public function create()
{
//
return view('admin.applications.create');
}
2022-11-27 02:34:36 +00:00
/**
* Display the specified resource.
*
2022-12-27 16:25:22 +00:00
* @param Application $application
2022-11-27 02:34:36 +00:00
*
2022-12-27 16:25:22 +00:00
* @return RedirectResponse
2022-11-27 02:34:36 +00:00
*/
public function show(Application $application)
{
//
return redirect()->route('admin.applications.edit', $application);
}
/**
* Show the form for editing the specified resource.
*
2022-12-27 16:25:22 +00:00
* @param Application $application
*
2022-11-27 02:34:36 +00:00
* @return View
*/
public function edit(Application $application)
{
//
return view('admin.applications.edit', compact('application'));
}
/**
* Update the specified resource in storage.
*
2022-12-27 16:25:22 +00:00
* @param Request $request
* @param Application $application
2022-11-27 02:34:36 +00:00
*
2022-12-27 16:25:22 +00:00
* @return RedirectResponse
2022-11-27 02:34:36 +00:00
*/
public function update(Request $request, Application $application)
{
//
$this->validate($request, [
'name' => 'required',
'description' => 'required',
'api_token' => 'required|unique:applications,api_token,' . $application->id,
]);
$application->update($request->all());
return back()->with('success', '应用程序已更新。');
}
/**
* Remove the specified resource from storage.
*
2022-12-27 16:25:22 +00:00
* @param Application $application
2022-11-27 02:34:36 +00:00
*
2022-12-27 16:25:22 +00:00
* @return RedirectResponse
2022-11-27 02:34:36 +00:00
*/
public function destroy(Application $application)
{
//
$application->delete();
return redirect()->route('admin.applications.index')->with('success', '应用程序已删除。');
}
}