浏览代码

OwnerMaterial添加Controller,Factory,Seeder,Model,Migration,路由

ajun 5 年之前
父节点
当前提交
8cbe390ee8

+ 29 - 0
app/Http/Controllers/OwnerMaterialController.php

@@ -0,0 +1,29 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\OwnerMaterial;
+use Illuminate\Http\Request;
+
+class OwnerMaterialController extends Controller
+{
+    public function index(Request $request)
+    {
+
+    }
+
+    public function storeApi()
+    {
+        
+    }
+
+    public function updateApi()
+    {
+        
+    }
+
+    public function destroyApi()
+    {
+        
+    }
+}

+ 28 - 0
app/OwnerMaterial.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Traits\LogModelChanging;
+
+class OwnerMaterial extends Model
+{
+    use LogModelChanging;
+    protected $fillable = ['owner_id','material_id','material_code','size','special','specification','initiator'];
+
+    public function owner()
+    {
+        return $this->belongsTo(Owner::class);
+    }
+
+    public function material()
+    {
+        return $this->belongsTo(Material::class);
+    }
+
+    public function initiator()
+    {
+        return $this->belongsTo(User::class,'initiator','id');
+    }
+}

+ 17 - 0
database/factories/OwnerMaterialFactory.php

@@ -0,0 +1,17 @@
+<?php
+
+/** @var \Illuminate\Database\Eloquent\Factory $factory */
+
+use App\OwnerMaterial;
+use Faker\Generator as Faker;
+
+$factory->define(OwnerMaterial::class, function (Faker $faker) {
+    return [
+        'owner_id' => 1,
+        'material_id' => 1,
+        'material_code' => \Illuminate\Support\Str::random(5),
+        'size' => \Illuminate\Support\Str::random(10),
+        'special'=>\Illuminate\Support\Str::random(10),
+        'specification' => \Illuminate\Support\Str::random(10),
+        'initiator'=>1];
+});

+ 1 - 1
database/migrations/2021_02_01_132214_create_materials_table.php

@@ -14,7 +14,7 @@ class CreateMaterialsTable extends Migration
     public function up()
     {
         Schema::create('materials', function (Blueprint $table) {
-            $table->id();
+            $table->bigIncrements('id');
             $table->string('code',20)->unique()->comment('编号');
             $table->string('name',50)->comment('名称');
             $table->timestamps();

+ 38 - 0
database/migrations/2021_02_01_172827_create_owner_material_table.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateOwnerMaterialTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('owner_material', function (Blueprint $table) {
+            $table->id();
+            $table->bigInteger('owner_id')->index()->comment('货主');
+            $table->bigInteger('material_id')->index()->comment('耗材');
+            $table->string('material_code',30)->comment('耗材编码');
+            $table->string('size')->comment('尺寸');
+            $table->string('special')->nullable()->comment('特殊要求');
+            $table->text('specification')->nullable()->comment('材质规格');
+            $table->bigInteger('initiator')->comment('创建者');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('owner_materials');
+    }
+}

+ 18 - 0
database/seeds/OwnerMaterialSeeder.php

@@ -0,0 +1,18 @@
+<?php
+
+use App\OwnerMaterial;
+use Illuminate\Database\Seeder;
+
+class OwnerMaterialSeeder extends Seeder
+{
+    /**
+     * Run the database seeds.
+     *
+     * @return void
+     */
+    public function run()
+    {
+        $ownerMaterials =  factory(OwnerMaterial::class)->times(120)->make()->toArray();
+        OwnerMaterial::query()->insert($ownerMaterials);
+    }
+}

+ 7 - 0
routes/apiLocal.php

@@ -115,3 +115,10 @@ Route::group(['prefix' => 'material'],function(){
     Route::post('update','MaterialController@updateApi');
     Route::delete('destroy/{id}','MaterialController@destroyApi');
 });
+
+/** 项目耗材 */
+Route::group(['prefix' => 'ownerMaterial'],function(){
+    Route::post('store','OwnerMaterialController@storeApi');
+    Route::post('update','OwnerMaterialController@updateApi');
+    Route::delete('destroy/{id}','OwnerMaterialController@destroyApi');
+});

+ 3 - 1
routes/web.php

@@ -197,7 +197,9 @@ Route::group(['prefix'=>'maintenance'],function(){
         Route::post("get",'RegionController@get');
     });
     /** 耗材 */
-    Route::get('material','MaterialController@index');
+    Route::get('material','MaterialController@index');;
+    /** 项目耗材 */
+    Route::get('ownerMaterial','OwnerMaterialController@index');
 
     Route::get('syncRedisLogs','LogController@syncRedisLogs');
     Route::resource('log', 'LogController');