Ver código fonte

insert info migration

azam 5 anos atrás
pai
commit
10ea07eeec

+ 0 - 85
app/Http/Controllers/CategoryController.php

@@ -1,85 +0,0 @@
-<?php
-
-namespace App\Http\Controllers;
-
-use App\Category;
-use Illuminate\Http\Request;
-
-class CategoryController extends Controller
-{
-    /**
-     * Display a listing of the resource.
-     *
-     * @return \Illuminate\Http\Response
-     */
-    public function index()
-    {
-        //
-    }
-
-    /**
-     * Show the form for creating a new resource.
-     *
-     * @return \Illuminate\Http\Response
-     */
-    public function create()
-    {
-        //
-    }
-
-    /**
-     * Store a newly created resource in storage.
-     *
-     * @param  \Illuminate\Http\Request  $request
-     * @return \Illuminate\Http\Response
-     */
-    public function store(Request $request)
-    {
-        //
-    }
-
-    /**
-     * Display the specified resource.
-     *
-     * @param  \App\Category  $category
-     * @return \Illuminate\Http\Response
-     */
-    public function show(Category $category)
-    {
-        //
-    }
-
-    /**
-     * Show the form for editing the specified resource.
-     *
-     * @param  \App\Category  $category
-     * @return \Illuminate\Http\Response
-     */
-    public function edit(Category $category)
-    {
-        //
-    }
-
-    /**
-     * Update the specified resource in storage.
-     *
-     * @param  \Illuminate\Http\Request  $request
-     * @param  \App\Category  $category
-     * @return \Illuminate\Http\Response
-     */
-    public function update(Request $request, Category $category)
-    {
-        //
-    }
-
-    /**
-     * Remove the specified resource from storage.
-     *
-     * @param  \App\Category  $category
-     * @return \Illuminate\Http\Response
-     */
-    public function destroy(Category $category)
-    {
-        //
-    }
-}

+ 72 - 0
packages/product/src/Http/Controllers/CategoryController.php

@@ -0,0 +1,72 @@
+<?php
+
+namespace Packages\Product\Http\Controllers;
+
+use App\Http\Controllers\Controller;
+use Packages\Product\Models\Category;
+use Illuminate\Http\Request;
+
+
+class CategoryController extends Controller
+{
+    public function __construct()
+    {
+        $this->middleware('auth');
+    }
+
+//    **************index*********
+    public function index()
+    {
+        $categories = Category::orderBy('id','DESC')->paginate(20);
+
+        return view('product::categories.index',compact('categories'));
+    }
+
+
+
+
+    public function create()
+    {
+        //
+    }
+
+
+
+
+
+    public function store(Request $request)
+    {
+        //
+    }
+
+
+
+
+    public function show(Category $category)
+    {
+        //
+    }
+
+
+
+
+    public function edit(Category $category)
+    {
+        //
+    }
+
+
+
+
+    public function update(Request $request, Category $category)
+    {
+        //
+    }
+
+
+
+    public function destroy(Category $category)
+    {
+        //
+    }
+}

+ 7 - 1
packages/product/src/Models/Category.php

@@ -4,9 +4,15 @@ namespace Packages\Product\Models;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;
 
-class Product extends Model
+class Category extends Model
 {
     use SoftDeletes;
 
     protected $guarded =[];
+
+    public function user()
+    {
+        return $this->belongsTo(User::class);
+    }
+
 }

+ 7 - 0
database/migrations/2020_06_20_171824_create_categories_table.php → packages/product/src/database/migrations/2020_06_20_171824_create_categories_table.php

@@ -15,7 +15,14 @@ class CreateCategoriesTable extends Migration
     {
         Schema::create('categories', function (Blueprint $table) {
             $table->id();
+            $table->string('title');
+            $table->string('discription');
+            $table->string('creator_id');
+            $table->string('slug')->unique();
+            $table->string('category_type');
+            $table->integer('parent')->default(0);
             $table->timestamps();
+
         });
     }
 

+ 4 - 1
packages/product/src/routes/web.php

@@ -8,6 +8,9 @@ Route::group([
 Route::resource('products','ProductController');
 Route::get('/status/{product}', 'ProductController@updatestatus')->name('products.status');
 Route::get('/type/{product}', 'ProductController@updatetype')->name('products.type');
+
+
+    Route::resource('categories', 'CategoryController');
 });
 
 
@@ -27,4 +30,4 @@ Route::get('/type/{product}', 'ProductController@updatetype')->name('products.ty
 // $b = new B();
 // $b->ss();
 
-// Facades\B::ss();
+// Facades\B::ss();

+ 0 - 64
packages/product/src/views/categories/categories.blade.php

@@ -1,64 +0,0 @@
-@extends('back.index')
-
-@section('title')
-    پنل دسته بندی - مدیریت کاربران
-@endsection
-@section('content1')
-    <!--==========================main============================-->
-
-    <div class=" main-panel col-12 col-sm-12 col-md-9 col-lg-9 col-xl-9 ">
-        <div class="container">
-            <h3 class="col-lg-12 col-md-12 col-sm-12 col-12">
-                پنل دسته بندی - مدیریت کاربران
-            </h3>
-            <a href="{{route('admin.categories.create')}}" class="btn btn-success">دسته بندی جدید</a>
-
-            <hr>
-
-            <div class="row container">
-
-                <div class="col-lg-12 grid-margin stretch-card">
-                    <div class="card">
-                        <div class="card-body">
-                            @include('back.users.messages')
-                            <table class="table table-hover">
-                                <thead>
-                                <tr>
-                                    <th>شماره</th>
-                                    <th>نام</th>
-                                    <th>نام مستعار</th>
-                                    <th>مدیریت</th>
-                                </tr>
-                                </thead>
-                                <tbody>
-                                @foreach($categories as $category)
-
-                                    <tr>
-                                        <td>{{$category->id}}</td>
-                                        <td>{{$category->name}}</td>
-                                        <td>{{$category->slug}}</td>
-
-                                        <td>
-                                            <a href="{{route('admin.categories.edit',$category->id)}}"><label class="badge badge-success">ویرایش</label></a>
-                                            <a href="{{route('admin.categories.destroy',$category->id)}}" onclick="return confirm('آیا آیتم مورد نظر حدف شود؟');"><label class="badge badge-danger">حذف</label></a>
-                                        </td>
-                                    </tr>
-                                @endforeach
-                                </tbody>
-                            </table>
-                        </div>
-                        {{$categories->links()}}
-                    </div>
-                </div>
-
-            </div>
-
-        </div>
-    </div>
-@endsection
-
-
-
-
-
-

+ 17 - 0
packages/product/src/views/categories/index.blade.php

@@ -0,0 +1,17 @@
+<div class="col-md-6 form-group">
+    <label for="parent" class="col-md-3 col-form-label">
+        <i class="fa fa-star text-danger"></i>
+        گروه</label>
+    <div class="col-md-9">
+        <select name="parent" id="parent">
+            <option value="">انتخاب</option>
+            @foreach(\App\Category::where('parent',0)->with('sub_category')->get() as $value)
+                <option value="{{ $value->id }}">{{ $value->title }}</option>
+                @if($value->sub_category->count())
+                    @php $i=2; @endphp
+                    @include('cat',['child' => $value->sub_category ,'i' => $i])
+                @endif
+            @endforeach
+        </select>
+    </div>
+</div>