|
@@ -0,0 +1,87 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace App\Http\Controllers\API;
|
|
|
+
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
+use App\Http\Requests\API\NamingRule\CreateOrUpdateRequest;
|
|
|
+use App\Http\Resources\API\NamingRuleResource;
|
|
|
+use App\Models\NamingRule;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
+
|
|
|
+class NameRuleController extends Controller
|
|
|
+{
|
|
|
+ /**
|
|
|
+ * Display a listing of the resource.
|
|
|
+ */
|
|
|
+ public function index(Request $request)
|
|
|
+ {
|
|
|
+ $namingRules = NamingRule::allowed()->with(['company'])->filter($request->all())->paginate();
|
|
|
+
|
|
|
+ return NamingRuleResource::collection($namingRules);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Store a newly created resource in storage.
|
|
|
+ */
|
|
|
+ public function store(CreateOrUpdateRequest $request)
|
|
|
+ {
|
|
|
+ $formData = $request->only(['name', 'status', 'company_id', 'global']);
|
|
|
+
|
|
|
+ if (! Auth::user()->super_admin) {
|
|
|
+ $formData['company_id'] = Auth::user()->company_id;
|
|
|
+ unset($formData['global']);
|
|
|
+ }
|
|
|
+
|
|
|
+ NamingRule::create($formData);
|
|
|
+
|
|
|
+ return $this->created();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Display the specified resource.
|
|
|
+ */
|
|
|
+ public function show(string $id)
|
|
|
+ {
|
|
|
+ $namingRule = NamingRule::query()->allowed()->findOrFail($id);
|
|
|
+
|
|
|
+ return new NamingRuleResource($namingRule);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Update the specified resource in storage.
|
|
|
+ */
|
|
|
+ public function update(CreateOrUpdateRequest $request, string $id)
|
|
|
+ {
|
|
|
+ $namingRule = NamingRule::query()->allowed()->findOrFail($id);
|
|
|
+
|
|
|
+ $namingRule->fill($request->only([
|
|
|
+ 'name', 'status', 'global'
|
|
|
+ ]));
|
|
|
+ $namingRule->save();
|
|
|
+
|
|
|
+ return $this->noContent();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Remove the specified resource from storage.
|
|
|
+ */
|
|
|
+ public function destroy(string $id)
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function enabled()
|
|
|
+ {
|
|
|
+ $namingRules = NamingRule::where('status', 1)->where(function ($query) {
|
|
|
+ return $query->where("company_id", Auth::user()->company_id)->orWhere([
|
|
|
+ 'company_id' => 0,
|
|
|
+ 'global' => 1
|
|
|
+ ]);
|
|
|
+ })->select(['id', 'name'])->get();
|
|
|
+
|
|
|
+ return $this->success([
|
|
|
+ 'data' => $namingRules
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+}
|