Kaynağa Gözat

check input search creator_id

azam 4 yıl önce
ebeveyn
işleme
c469e49344

+ 4 - 2
app/Http/Controllers/Panel/Categories/CategoryController.php

@@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Http\Request;
 
 
+
 class CategoryController extends Controller
 {
     /**
@@ -17,6 +18,7 @@ class CategoryController extends Controller
      */
     public function index()
     {
+
         $categories = Category::orderBy('id','DESC');
 
              if (request()->has('categoryName') && request('categoryName') != '')
@@ -26,8 +28,8 @@ class CategoryController extends Controller
             $categories = $categories->whereRaw('slug = ?', [request('categorySlug')]);
 
         if (request()->has('creatorId') && request('creatorId') != '')
-          $categories = $categories->whereHas('users', function (Builder $query) {
-              $query->whereRaw('id = ?', [request('creatorId')]);
+          $categories = $categories->whereHas('user', function (Builder $query) {
+              $query->whereRaw('name= ?', [request('creatorId')]);
            });
         $categories = $categories->paginate();
         return view('panel.categories.index',compact('categories'));

+ 5 - 1
packages/product/src/Http/Controllers/ProductController.php

@@ -35,9 +35,13 @@ class ProductController extends Controller
 
         if (request()->has('productName') && request('productName') != '')
             $products = $products->whereRaw('title = ?', [request('productName')]);
-
+        if (request()->has('creatorId') && request('creatorId') != '')
+            $products = $products->whereHas('user', function (Builder $query) {
+                $query->whereRaw('name= ?', [request('creatorId')]);
+            });
         $products = $products->paginate();
 
+
         return view('product::index', compact('products', 'categories'));
 
     }

+ 33 - 20
packages/product/src/views/index.blade.php

@@ -6,7 +6,7 @@
                 margin-top: 10px;
             }
             .searchNaum{
-                display: none;
+
                 margin: 20px;
             }
         </style>
@@ -49,24 +49,37 @@
                                             @endforeach
                                         </select>
                                     </div>
-                                    <div class="col">
-                                        <label for="categories">{{ __('  وضعیت:') }}</label>
-                                        <select type="text" class="form-control" placeholder="وضعیت..."
-                                                name="productStatus" value="{{ request()->query('productStatus') }}">
-                                            <option value="">همه</option>
-                                            <option value=1 {{(request()->has('productStatus') && request()->query('productStatus') == "1") ? 'selected'
+
+                                </div>
+                              <div class="form-row">
+                                  <div class="col">
+                                      <label for="categories">{{ __('  وضعیت:') }}</label>
+                                      <select type="text" class="form-control" placeholder="وضعیت..."
+                                              name="productStatus" value="{{ request()->query('productStatus') }}">
+                                          <option value="">همه</option>
+                                          <option value=1 {{(request()->has('productStatus') && request()->query('productStatus') == "1") ? 'selected'
                                                : ''}}>موجود
-                                            </option>
-                                            <option value=0 {{(request()->has('productStatus') && request()->query('productStatus') ==" 0") ?
+                                          </option>
+                                          <option value=0 {{(request()->has('productStatus') && request()->query('productStatus') ==" 0") ?
                                               'selected': ''}}>ناموجود
-                                            </option>
-                                        </select>
-                                    </div>
-                                </div>
+                                          </option>
+                                      </select>
+                                  </div>
+                                  <div class="col">
+                                      <label for="categories">{{ __('  نام ثبت کننده:') }}</label>
+                                      <input type="text" class="form-control" placeholder="ایجاد کننده دسته بندی..."
+                                             name="creatorId" value="{{ request()->query('creatorId') }}">
+
+
+                                  </div>
+
+                              </div>
 
                                 <button type="submit" class="btn btn-primary float-left btnSearch" id="showProduct">جستجو
                                 </button>
-                                <p class="searchNaum">{{$products->total()}}{{ __(' :مورد یافت شد.') }}</p>
+                              @if($products->total() > 0)
+                                <p class="searchNaum">نتایج یافت شده: {{$products->total()}}</p>
+                                  @endif
                             </form>
 
                             <div class="mt-4">
@@ -138,13 +151,13 @@
         </div>
     @endslot
     @slot('script')
-        <script>
+{{--        <script>--}}
 
 
-            $("#showProduct").click(function(e){
-                e.preventDefault();
-                $(".searchNaum").show();
-            });
-        </script>
+{{--            $("#showProduct").click(function(e){--}}
+{{--                e.preventDefault();--}}
+{{--                $(".searchNaum").show();--}}
+{{--            });--}}
+{{--        </script>--}}
     @endslot
 @endcomponent

+ 8 - 16
resources/views/panel/categories/create.blade.php

@@ -1,5 +1,4 @@
 @component('panel.layouts.component', ['title' => 'ثبت دسته جدید'])
-
     @slot('style')
         <style>
             .card-header {
@@ -7,7 +6,6 @@
             }
 
             .form-control {
-
                 background-color: hsl(315, 22%, 86%);
             }
 
@@ -22,12 +20,10 @@
     @endslot
     @slot('subject')
         <h1><i class="fa fa-users"></i> ثبت دسته جدید </h1>
-
     @endslot
     @slot('breadcrumb')
         <li class="breadcrumb-item">دسته بندی محصولات</li>
     @endslot
-
     @slot('content')
         <div class="auth-background h-auto py-5">
             <div class="container py-5">
@@ -35,38 +31,32 @@
                     <div class="col-lg-11 col-md-11 mx-auto">
                         <div class="card">
                             <div class="card-header"><strong>{{ __('ثبت دسته بندی جدید') }}</strong></div>
-
                             <div class="card-body mx-lg-5 px-lg-3">
                                 <form method="POST" action="{{ route('categories.store') }}">
                                     @csrf
-
                                     <div class="form-group">
-                                        <label for="title">{{ __('category.title') }}</label><i class="required">&nbsp; *</i>
+                                        <label for="title">{{ __('category.title') }}</label><i class="required">&nbsp;
+                                            *</i>
                                         <input id="title" type="text"
                                                class="form-control @error('title') is-invalid @enderror" name="title"
-                                               value="{{ old('title') }}"  autocomplete="title" autofocus>
-
+                                               value="{{ old('title') }}" autocomplete="title" autofocus>
                                         @error('title')
                                         <span class="invalid-feedback" role="alert">
                                             <strong>{{ $message }}</strong>
                                         </span>
                                         @enderror
-
                                     </div>
-
                                     <div class="form-group">
                                         <label for="slug">{{ __('category.slug') }}</label>
                                         <input id="slug" type="text"
                                                class="form-control @error('slug') is-invalid @enderror"
                                                name="slug" value="{{ old('slug') }}"
                                                autocomplete="slug" autofocus>
-
                                         @error('slug')
                                         <span class="invalid-feedback" role="alert">
                                             <strong>{{ $message }}</strong>
                                         </span>
                                         @enderror
-
                                     </div>
                                     <div class="form-group">
                                         <label for="parent">{{ __('category.parent') }}</label><i class="required">&nbsp;*</i>
@@ -84,12 +74,13 @@
                                     </div>
 
                                     <div class="form-group">
-                                        <label for="category_type">{{ __('category.category_type') }}</label><i class="required">&nbsp;
+                                        <label for="category_type">{{ __('category.category_type') }}</label><i
+                                            class="required">&nbsp;
                                             *</i>
                                         <select id="category_type" type="text"
                                                 class="form-control @error('category_type') is-invalid @enderror"
                                                 name="category_type"
-                                                 autocomplete="category_type">
+                                                autocomplete="category_type">
                                             <option value="">انتخاب کنید</option>
                                             <option value="0">محصولات</option>
                                             <option value="1">اخبار</option>
@@ -105,7 +96,8 @@
 
 
                                     <div class="form-group">
-                                        <label for="discription">{{ __('category.discription') }}</label><i class="required">&nbsp; *</i>
+                                        <label for="discription">{{ __('category.discription') }}</label><i
+                                            class="required">&nbsp; *</i>
                                         <textarea id="discription" type="text"
                                                   class="form-control @error('discription') is-invalid @enderror"
                                                   name="discription"

+ 38 - 66
resources/views/panel/categories/index.blade.php

@@ -1,15 +1,16 @@
 @component('panel.layouts.component', ['title' => 'دسته بندی '])
-
     @slot('style')
+        <style>
+            .btnSearch {margin-top: 10px;}
+            .searchNaum {margin: 20px;}
+        </style>
     @endslot
-
     @slot('subject')
-        <h1><i class="fa fa-users"></i> دسته بندی  </h1>
+        <h1><i class="fa fa-users"></i> دسته بندی </h1>
         <p>لیست دسته بندی های تعریف شده برای مدیریت سطوح دسترسی.</p>
     @endslot
-
     @slot('breadcrumb')
-        <li class="breadcrumb-item">دسته بندی </li>
+        <li class="breadcrumb-item">دسته بندی</li>
     @endslot
     @slot('content')
         <div class="row">
@@ -18,33 +19,31 @@
                 @endcomponent
                 @component('components.collapse-card' , ['title' => 'جست جو دسته بندی'])
                     @slot('body')
-        <form method="GET" action="">
-            <div class="form-row">
-                <div class="col">
-                    <label for="categories">{{ __(' نام دسته بندی:') }}</label>
-                    <input type="text" class="form-control" placeholder="محصول..."
-                           name="categoryName" value="{{ request()->query('categoryName') }}">
-                </div>
-                <div class="col">
-                    <label for="categories">{{ __(' slug:') }}</label>
-                    <input type="text" class="form-control" placeholder="دسته بندی..."
-                            name="categorySlug"
-                            value="{{ request()->query('categorySlug') }}">
-
-                </div>
-                <div class="col">
-                    <label for="categories">{{ __('  نام ثبت کننده:') }}</label>
-                    <input type="text" class="form-control" placeholder="ایجاد کننده دسته بندی..."
-                            name="creatorId" value="{{ request()->query('creatorId') }}">
-
-
-                </div>
-            </div>
-
-            <button type="submit" class="btn btn-primary float-left btnSearch" id="show">جستجو
-            </button>
-            <p class="searchNaum">{{$categories->count()}}{{ __(' :مورد یافت شد.') }}</p>
-        </form>
+                        <form method="GET" action="">
+                            <div class="form-row">
+                                <div class="col">
+                                    <label for="categories">{{ __(' نام دسته بندی:') }}</label>
+                                    <input type="text" class="form-control" placeholder="محصول..."
+                                           name="categoryName" value="{{ request()->query('categoryName') }}">
+                                </div>
+                                <div class="col">
+                                    <label for="categories">{{ __(' slug:') }}</label>
+                                    <input type="text" class="form-control" placeholder="دسته بندی..."
+                                           name="categorySlug"
+                                           value="{{ request()->query('categorySlug') }}">
+                                </div>
+                                <div class="col">
+                                    <label for="categories">{{ __('  نام ثبت کننده:') }}</label>
+                                    <input type="text" class="form-control" placeholder="ایجاد کننده دسته بندی..."
+                                           name="creatorId" value="{{ request()->query('creatorId') }}">
+                                </div>
+                            </div>
+                            <button type="submit" class="btn btn-primary float-left btnSearch" id="show">جستجو
+                            </button>
+                            @if($categories->total() > 0)
+                                <p class="searchNaum">نتایج یافت شده:{{$categories->total()}}</p>
+                            @endif
+                        </form>
 
                         <div class="mt-4">
                             <a href="{{ route('categories.create') }}" type="button" class="btn btn-primary"><i
@@ -66,37 +65,18 @@
                             @endslot
                             @slot('tbody')
                                 @forelse ($categories as $category)
-
                                     <tr>
-                                        <td>
-                                            {{$category->id}}
-                                        </td>
-                                        <td>
-                                            {{$category->title}}
-                                        </td>
-                                        <td>
-                                            {{$category->slug}}
-                                        </td>
-                                        <td>
-                                            {{$category->category_type}}
-                                        </td>
-                                        <td>
-                                            {{$category->parent}}
-                                        </td>
+                                        <td>{{$category->id}}</td>
+                                        <td>{{$category->title}}</td>
+                                        <td>{{$category->slug}}</td>
+                                        <td>{$category->category_type}}</td>
+                                        <td>{{$category->parent}}</td>
                                         <td><?php  echo mb_substr(strip_tags($category->discription), 0, 15, 'UTF8') . '...'?></td>
-
-                                        <td>
-                                            {{$category->user->name}}
-                                        </td>
-
+                                        <td>{{$category->user->name}}</td>
                                         <td class="d-flex">
                                             <a href="{{route('categories.edit', $category->id)}}"
                                                class="btn btn-sm btn-primary mr-2">ویرایش</a>
-                                            <form
-                                                action="{{route('categories.destroy', $category->id)}}"
-                                                method="POST"
-                                                onsubmit="return confirm('آیا مطمئن هستید؟');"
-                                            >
+                                            <form action="{{route('categories.destroy', $category->id)}}" method="POST" onsubmit="return confirm('آیا مطمئن هستید؟');">
                                                 @csrf
                                                 @method('DELETE')
                                                 <button type="submit" class="btn btn-sm btn-danger">حذف</button>
@@ -109,23 +89,15 @@
                                     </tr>
                                 @endforelse
                             @endslot
-
                         @endcomponent
-
                         {{--Paginate section--}}
-
                         {{ $categories->withQueryString()->links() }}
-
                     @endslot
                 @endcomponent
             </div>
         </div>
-
-
     @endslot
-
     @slot('script')
     @endslot
-
 @endcomponent