浏览代码

Ограничение для менеджеров на импорт и редактирование продуктов

Alexander Musikhin 2 年之前
父节点
当前提交
0436bae23a

+ 5 - 1
app/Http/Controllers/ProductController.php

@@ -6,6 +6,7 @@ use App\Http\Requests\SaveProductRequest;
 use App\Models\Product;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Redirect;
+use Illuminate\Support\Facades\URL;
 use Illuminate\Support\Str;
 
 
@@ -131,8 +132,11 @@ class ProductController extends Controller
 
     public function save_product(SaveProductRequest $request)
     {
+
+
         Product::query()->where('id', $request->validated('id'))->update($request->validated());
-        return redirect()->route('index');
+        return redirect($request->prev_url);
+//        return redirect()->route('index');
     }
 
     public function upload_image(Request $request){

+ 3 - 1
resources/views/layouts/app.blade.php

@@ -32,7 +32,9 @@
                 <div class="collapse navbar-collapse" id="navbarSupportedContent">
                     <!-- Left Side Of Navbar -->
                     <ul class="navbar-nav me-auto">
-                        <li class="nav-item"><a href="#" onclick="document.getElementById('import-form').click()" class="nav-link">Импорт из XLS</a></li>
+                        @if(\Illuminate\Support\Facades\Session::get('user')['role'] == 1)
+                            <li class="nav-item"><a href="#" onclick="document.getElementById('import-form').click()" class="nav-link">Импорт из XLS</a></li>
+                        @endif
                     </ul>
 
                     <!-- Right Side Of Navbar -->

+ 20 - 11
resources/views/products/product.blade.php

@@ -1,6 +1,13 @@
 @extends('layouts.app')
 
 @section('content')
+
+    @php
+    $disabled = 'disabled';
+    if(\Illuminate\Support\Facades\Session::get('user')['role'] == 1) $disabled = ''
+    @endphp
+
+
     <div class="container-fluid">
         <div class="row">
             <div class="col-sm-12 col-md-6">
@@ -12,11 +19,11 @@
                             <label for="article" class="form-label">Артикул</label>
                             <input class="form-control" id="article" value="{{ $product->article }}"
                                    disabled>
-                            <input type="hidden" name="id" value="{{ $product->id }}">
+                            <input type="hidden" name="id" value="{{ $product->id }}" {{ $disabled }}>
                         </div>
                         <div class="col-6">
                             <label for="series" class="form-label">Серия</label>
-                            <input class="form-control @error('series') border-danger @enderror"
+                            <input class="form-control @error('series') border-danger @enderror"  {{ $disabled }}
                                    name="series" id="series" value="{{ old('series', $product->series) }}">
                             @error('series')
                             <div class="form-text text-danger" id="titleError">
@@ -29,7 +36,7 @@
                     <div class="row mt-3">
                         <div class="col-6">
                             <label for="name" class="form-label">Наименовение</label>
-                            <input class="form-control @error('name') border-danger @enderror"
+                            <input class="form-control @error('name') border-danger @enderror"  {{ $disabled }}
                                    name="name" id="name" value="{{ old('name', $product->name) }}">
                             @error('name')
                             <div class="form-text text-danger" id="titleError">
@@ -39,7 +46,7 @@
                         </div>
                         <div class="col-6">
                             <label for="name_for_form" class="form-label">Наименование под образец формы</label>
-                            <input class="form-control @error('name_for_form') border-danger @enderror"
+                            <input class="form-control @error('name_for_form') border-danger @enderror"  {{ $disabled }}
                                    name="name_for_form" id="name_for_form"
                                    value="{{ old('name_for_form', $product->name_for_form) }}">
                             @error('name_for_form')
@@ -54,7 +61,7 @@
                         <div class="col-6">
                             <label for="product_group" class="form-label">Группа</label>
                             <input class="form-control @error('product_group') border-danger @enderror"
-                                   name="product_group" id="product_group"
+                                   name="product_group" id="product_group"  {{ $disabled }}
                                    value="{{ old('product_group', $product->product_group) }}">
                             @error('product_group')
                             <div class="form-text text-danger" id="titleError">
@@ -65,7 +72,7 @@
                         <div class="col-6">
                             <label for="price" class="form-label">Цена</label>
                             <input type="number" class="form-control @error('price') border-danger @enderror"
-                                   name="price" id="price"
+                                   name="price" id="price"  {{ $disabled }}
                                    value="{{ old('price', $product->price) }}">
                             @error('price')
                             <div class="form-text text-danger" id="titleError">
@@ -77,7 +84,7 @@
 
                     <label for="characteristics" class="form-label mt-3">Характеристики</label>
                     <textarea class="form-control @error('characteristics') border-danger @enderror"
-                              name="characteristics" rows="4"
+                              name="characteristics" rows="4" {{ $disabled }}
                               id="characteristics">{{ old('characteristics', $product->characteristics) }}</textarea>
                     @error('characteristics')
                     <div class="form-text text-danger" id="titleError">
@@ -87,7 +94,7 @@
 
                     <label for="tech_description" class="form-label mt-3">Техническое описание</label>
                     <textarea class="form-control @error('tech_description') border-danger @enderror"
-                              name="tech_description" rows="5"
+                              name="tech_description" rows="5" {{ $disabled }}
                               id="tech_description">{{ old('tech_description', $product->tech_description) }}</textarea>
                     @error('tech_description')
                     <div class="form-text text-danger" id="titleError">
@@ -98,7 +105,7 @@
                     <label for="tech_description_short" class="form-label mt-3">Техническое описание сокращенное без
                         артикула</label>
                     <textarea class="form-control  @error('tech_description_short') border-danger @enderror"
-                              name="tech_description_short" rows="5"
+                              name="tech_description_short" rows="5" {{ $disabled }}
                               id="tech_description_short">{{
                                 old('tech_description_short', $product->tech_description_short) }}</textarea>
                     @error('tech_description_short')
@@ -108,14 +115,16 @@
                     @enderror
 
                     <div class="col-12 text-center mt-3">
-                        <button type="submit" class="btn btn-primary">Сохранить</button>
+                        <input type="hidden" name="prev_url" value="{{ URL::previous() }}">
+                        <button {{ $disabled }} type="submit" class="btn btn-primary">Сохранить</button>
+                        <a href="{{ URL::previous() }}" class="btn btn-dark">Назад</a>
                     </div>
                 </form>
             </div>
 
             <div class="col-sm-12 col-md-6">
                 <div class="col-12 text-end">
-                    <button class="btn btn-primary" onclick="document.getElementById('upload-image-form').click()">
+                    <button {{ $disabled }} class="btn btn-primary" onclick="document.getElementById('upload-image-form').click()">
                         Загрузить
                     </button>
                     <br>