储存策略添加

This commit is contained in:
Wisp X 2022-01-26 16:40:43 +08:00
parent d3172f1258
commit e42ac5de3b
7 changed files with 86 additions and 118 deletions

View File

@ -4,10 +4,12 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\StrategyRequest;
use App\Models\Group;
use App\Models\Strategy;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
use Illuminate\View\View;
class StrategyController extends Controller
@ -33,9 +35,18 @@ class StrategyController extends Controller
public function create(StrategyRequest $request): Response
{
$group = new Strategy();
$group->fill($request->validated());
$group->save();
$validated = $request->validated();
$strategy = new Strategy($validated);
DB::transaction(function () use ($strategy, $validated) {
$strategy->save();
DB::table('group_strategy')->insert(
Group::query()
->whereIn('id', $validated['groups'] ?: [])
->pluck('id')
->transform(fn ($id) => ['group_id' => $id, 'strategy_id' => $strategy->id])
->toArray()
);
});
return $this->success('创建成功');
}

View File

@ -15,8 +15,10 @@ class StrategyRequest extends FormRequest
public function rules()
{
return [
'groups' => 'array',
'name' => 'required|max:60',
'intro' => 'max:2000',
'key' => 'required|integer',
'configs.root' => 'max:1000',
'configs.domain' => 'required|url',
];

View File

@ -5,6 +5,7 @@ namespace App\Models;
use App\Enums\Strategy\LocalOption;
use App\Enums\StrategyKey;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@ -60,6 +61,13 @@ class Strategy extends Model
});
}
public function intro(): Attribute
{
return new Attribute(
set: fn ($value) => $value ?: '',
);
}
public function groups(): BelongsToMany
{
return $this->belongsToMany(Group::class, 'group_strategy', 'group_id', 'strategy_id');

View File

@ -7,9 +7,9 @@
"require": {
"php": "^8.0",
"fruitcake/laravel-cors": "^2.0.5",
"guzzlehttp/guzzle": "^7.0.1",
"guzzlehttp/guzzle": "^7.2",
"intervention/image": "^2.7",
"laravel/breeze": "dev-laravel9",
"laravel/breeze": "^1.7",
"laravel/framework": "^9.0",
"laravel/sanctum": "^2.14",
"laravel/tinker": "^2.7",

64
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "c36bb3f58e9cf016cf72e03a16057222",
"content-hash": "6c5939df8bcb6a36d07ae450be91e1f5",
"packages": [
{
"name": "asm89/stack-cors",
@ -1123,16 +1123,16 @@
},
{
"name": "laravel/breeze",
"version": "dev-laravel9",
"version": "v1.7.1",
"source": {
"type": "git",
"url": "https://github.com/laravel/breeze.git",
"reference": "644f7475d6c190de4cc6c44f9a1fb6c104b247fb"
"reference": "671c552ae193b3e712039a17a2d75f436a0a790a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/breeze/zipball/644f7475d6c190de4cc6c44f9a1fb6c104b247fb",
"reference": "644f7475d6c190de4cc6c44f9a1fb6c104b247fb",
"url": "https://api.github.com/repos/laravel/breeze/zipball/671c552ae193b3e712039a17a2d75f436a0a790a",
"reference": "671c552ae193b3e712039a17a2d75f436a0a790a",
"shasum": "",
"mirrors": [
{
@ -1182,7 +1182,7 @@
"issues": "https://github.com/laravel/breeze/issues",
"source": "https://github.com/laravel/breeze"
},
"time": "2022-01-11T13:08:19+00:00"
"time": "2022-01-25T15:13:03+00:00"
},
{
"name": "laravel/framework",
@ -1580,16 +1580,16 @@
},
{
"name": "league/commonmark",
"version": "2.2.0",
"version": "2.2.1",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
"reference": "c5aadcc15548629787d02b86a7afef03b46271b5"
"reference": "f8afb78f087777b040e0ab8a6b6ca93f6fc3f18a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/c5aadcc15548629787d02b86a7afef03b46271b5",
"reference": "c5aadcc15548629787d02b86a7afef03b46271b5",
"url": "https://api.github.com/repos/thephpleague/commonmark/zipball/f8afb78f087777b040e0ab8a6b6ca93f6fc3f18a",
"reference": "f8afb78f087777b040e0ab8a6b6ca93f6fc3f18a",
"shasum": "",
"mirrors": [
{
@ -1603,7 +1603,7 @@
"league/config": "^1.1.1",
"php": "^7.4 || ^8.0",
"psr/event-dispatcher": "^1.0",
"symfony/deprecation-contracts": "^v2.1 || ^3.0",
"symfony/deprecation-contracts": "^2.1 || ^3.0",
"symfony/polyfill-php80": "^1.15"
},
"require-dev": {
@ -1686,7 +1686,7 @@
"type": "tidelift"
}
],
"time": "2022-01-22T14:06:22+00:00"
"time": "2022-01-25T14:37:33+00:00"
},
{
"name": "league/config",
@ -2036,16 +2036,16 @@
},
{
"name": "nesbot/carbon",
"version": "2.55.2",
"version": "2.56.0",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "8c2a18ce3e67c34efc1b29f64fe61304368259a2"
"reference": "626ec8cbb724cd3c3400c3ed8f730545b744e3f4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/8c2a18ce3e67c34efc1b29f64fe61304368259a2",
"reference": "8c2a18ce3e67c34efc1b29f64fe61304368259a2",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/626ec8cbb724cd3c3400c3ed8f730545b744e3f4",
"reference": "626ec8cbb724cd3c3400c3ed8f730545b744e3f4",
"shasum": "",
"mirrors": [
{
@ -2068,7 +2068,7 @@
"kylekatarnls/multi-tester": "^2.0",
"phpmd/phpmd": "^2.9",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.54",
"phpstan/phpstan": "^0.12.54 || ^1.0",
"phpunit/phpunit": "^7.5.20 || ^8.5.14",
"squizlabs/php_codesniffer": "^3.4"
},
@ -2134,7 +2134,7 @@
"type": "tidelift"
}
],
"time": "2021-12-03T14:59:52+00:00"
"time": "2022-01-21T17:08:38+00:00"
},
{
"name": "nette/schema",
@ -2206,16 +2206,16 @@
},
{
"name": "nette/utils",
"version": "v3.2.6",
"version": "v3.2.7",
"source": {
"type": "git",
"url": "https://github.com/nette/utils.git",
"reference": "2f261e55bd6a12057442045bf2c249806abc1d02"
"reference": "0af4e3de4df9f1543534beab255ccf459e7a2c99"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nette/utils/zipball/2f261e55bd6a12057442045bf2c249806abc1d02",
"reference": "2f261e55bd6a12057442045bf2c249806abc1d02",
"url": "https://api.github.com/repos/nette/utils/zipball/0af4e3de4df9f1543534beab255ccf459e7a2c99",
"reference": "0af4e3de4df9f1543534beab255ccf459e7a2c99",
"shasum": "",
"mirrors": [
{
@ -2291,9 +2291,9 @@
],
"support": {
"issues": "https://github.com/nette/utils/issues",
"source": "https://github.com/nette/utils/tree/v3.2.6"
"source": "https://github.com/nette/utils/tree/v3.2.7"
},
"time": "2021-11-24T15:47:23+00:00"
"time": "2022-01-24T11:29:14+00:00"
},
{
"name": "nikic/php-parser",
@ -5666,16 +5666,16 @@
},
{
"name": "voku/portable-ascii",
"version": "1.5.6",
"version": "1.6.1",
"source": {
"type": "git",
"url": "https://github.com/voku/portable-ascii.git",
"reference": "80953678b19901e5165c56752d087fc11526017c"
"reference": "87337c91b9dfacee02452244ee14ab3c43bc485a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/voku/portable-ascii/zipball/80953678b19901e5165c56752d087fc11526017c",
"reference": "80953678b19901e5165c56752d087fc11526017c",
"url": "https://api.github.com/repos/voku/portable-ascii/zipball/87337c91b9dfacee02452244ee14ab3c43bc485a",
"reference": "87337c91b9dfacee02452244ee14ab3c43bc485a",
"shasum": "",
"mirrors": [
{
@ -5718,7 +5718,7 @@
],
"support": {
"issues": "https://github.com/voku/portable-ascii/issues",
"source": "https://github.com/voku/portable-ascii/tree/1.5.6"
"source": "https://github.com/voku/portable-ascii/tree/1.6.1"
},
"funding": [
{
@ -5742,7 +5742,7 @@
"type": "tidelift"
}
],
"time": "2020-11-12T00:07:28+00:00"
"time": "2022-01-24T18:55:24+00:00"
},
{
"name": "webmozart/assert",
@ -8639,9 +8639,7 @@
],
"aliases": [],
"minimum-stability": "dev",
"stability-flags": {
"laravel/breeze": 20
},
"stability-flags": [],
"prefer-stable": true,
"prefer-lowest": false,
"platform": {

99
public/css/app.css vendored
View File

@ -850,6 +850,9 @@ select {
.h-4 {
height: 1rem;
}
.h-9 {
height: 2.25rem;
}
.h-20 {
height: 5rem;
}
@ -871,9 +874,6 @@ select {
.h-7 {
height: 1.75rem;
}
.h-9 {
height: 2.25rem;
}
.h-6 {
height: 1.5rem;
}
@ -1172,9 +1172,6 @@ select {
.rounded {
border-radius: 0.25rem;
}
.rounded-none {
border-radius: 0px;
}
.rounded-l-md {
border-top-left-radius: 0.375rem;
border-bottom-left-radius: 0.375rem;
@ -1203,6 +1200,9 @@ select {
.border-b-2 {
border-bottom-width: 2px;
}
.border-l-0 {
border-left-width: 0px;
}
.border-t {
border-top-width: 1px;
}
@ -1212,12 +1212,6 @@ select {
.border-b {
border-bottom-width: 1px;
}
.border-r-0 {
border-right-width: 0px;
}
.border-l-0 {
border-left-width: 0px;
}
.border-solid {
border-style: solid;
}
@ -1275,6 +1269,10 @@ select {
--tw-bg-opacity: 1;
background-color: rgb(248 113 113 / var(--tw-bg-opacity));
}
.bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
}
.bg-gray-500 {
--tw-bg-opacity: 1;
background-color: rgb(107 114 128 / var(--tw-bg-opacity));
@ -1291,10 +1289,6 @@ select {
--tw-bg-opacity: 1;
background-color: rgb(31 41 55 / var(--tw-bg-opacity));
}
.bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
}
.bg-gray-600 {
--tw-bg-opacity: 1;
background-color: rgb(75 85 99 / var(--tw-bg-opacity));
@ -1319,14 +1313,6 @@ select {
--tw-bg-opacity: 1;
background-color: rgb(55 65 81 / var(--tw-bg-opacity));
}
.bg-yellow-400 {
--tw-bg-opacity: 1;
background-color: rgb(250 204 21 / var(--tw-bg-opacity));
}
.bg-yellow-300 {
--tw-bg-opacity: 1;
background-color: rgb(253 224 71 / var(--tw-bg-opacity));
}
.bg-opacity-75 {
--tw-bg-opacity: 0.75;
}
@ -1349,15 +1335,15 @@ select {
.p-2 {
padding: 0.5rem;
}
.p-1 {
padding: 0.25rem;
}
.p-3 {
padding: 0.75rem;
}
.p-6 {
padding: 1.5rem;
}
.p-1 {
padding: 0.25rem;
}
.px-4 {
padding-left: 1rem;
padding-right: 1rem;
@ -1418,14 +1404,6 @@ select {
padding-top: 3.5rem;
padding-bottom: 3.5rem;
}
.px-1\.5 {
padding-left: 0.375rem;
padding-right: 0.375rem;
}
.px-1 {
padding-left: 0.25rem;
padding-right: 0.25rem;
}
.pb-6 {
padding-bottom: 1.5rem;
}
@ -1589,6 +1567,10 @@ select {
--tw-text-opacity: 1;
color: rgb(79 70 229 / var(--tw-text-opacity));
}
.text-yellow-500 {
--tw-text-opacity: 1;
color: rgb(234 179 8 / var(--tw-text-opacity));
}
.text-blue-500 {
--tw-text-opacity: 1;
color: rgb(59 130 246 / var(--tw-text-opacity));
@ -1613,10 +1595,6 @@ select {
--tw-text-opacity: 1;
color: rgb(71 85 105 / var(--tw-text-opacity));
}
.text-yellow-500 {
--tw-text-opacity: 1;
color: rgb(234 179 8 / var(--tw-text-opacity));
}
.underline {
-webkit-text-decoration-line: underline;
text-decoration-line: underline;
@ -1655,11 +1633,6 @@ select {
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color), 0 1px 2px -1px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.shadow-none {
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.outline-none {
outline: 2px solid transparent;
outline-offset: 2px;
@ -1772,14 +1745,6 @@ select {
--tw-text-opacity: 1;
color: rgb(129 140 248 / var(--tw-text-opacity));
}
.hover\:text-white:hover {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.hover\:text-gray-900:hover {
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
}
.hover\:text-indigo-900:hover {
--tw-text-opacity: 1;
color: rgb(49 46 129 / var(--tw-text-opacity));
@ -1788,6 +1753,14 @@ select {
--tw-text-opacity: 1;
color: rgb(127 29 29 / var(--tw-text-opacity));
}
.hover\:text-white:hover {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.hover\:text-gray-900:hover {
--tw-text-opacity: 1;
color: rgb(17 24 39 / var(--tw-text-opacity));
}
.hover\:text-gray-700:hover {
--tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity));
@ -1799,10 +1772,6 @@ select {
--tw-border-opacity: 1;
border-color: rgb(147 197 253 / var(--tw-border-opacity));
}
.focus\:border-indigo-500:focus {
--tw-border-opacity: 1;
border-color: rgb(99 102 241 / var(--tw-border-opacity));
}
.focus\:border-indigo-300:focus {
--tw-border-opacity: 1;
border-color: rgb(165 180 252 / var(--tw-border-opacity));
@ -1811,18 +1780,10 @@ select {
--tw-border-opacity: 1;
border-color: rgb(209 213 219 / var(--tw-border-opacity));
}
.focus\:border-gray-500:focus {
--tw-border-opacity: 1;
border-color: rgb(107 114 128 / var(--tw-border-opacity));
}
.focus\:bg-gray-100:focus {
--tw-bg-opacity: 1;
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
}
.focus\:bg-white:focus {
--tw-bg-opacity: 1;
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
.focus\:text-gray-700:focus {
--tw-text-opacity: 1;
color: rgb(55 65 81 / var(--tw-text-opacity));
@ -1845,11 +1806,6 @@ select {
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
.focus\:ring-0:focus {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
.focus\:ring-indigo-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(99 102 241 / var(--tw-ring-opacity));
@ -2003,11 +1959,6 @@ select {
padding-top: 0px;
}
.sm\:text-sm {
font-size: 0.875rem;
line-height: 1.25rem;
}
.sm\:text-2xl {
font-size: 1.5rem;
line-height: 2rem;

View File

@ -10,12 +10,10 @@
<div class="col-span-6">
<label class="block">
<span class="text-gray-700">选择角色组</span>
<x-select class="block w-full mt-1 form-multiselect" multiple>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
<option>Option 4</option>
<option>Option 5</option>
<x-select name="groups[]" class="block w-full mt-1 form-multiselect" multiple>
@foreach(\App\Models\Group::query()->get() as $group)
<option value="{{ $group->id }}">{{ $group->name }}</option>
@endforeach
</x-select>
</label>
</div>