我将如何将数据插入到不同的拖放表中?

发布于 2025-02-11 23:35:36 字数 5738 浏览 1 评论 0原文

我将如何将数据插入到不同的拖放表中? 亲爱的所有开发人员 我将如何在函数存储食谱中创建数据插入不同的拖放表(缩略图 - 食谱),并且我与表Thumbnail_id forefer键有关系。 桌子缩略图:

Schema::create('thumbnails', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->charset = 'utf8mb4';
        $table->collation = 'utf8mb4_unicode_ci';
        //$table->comment('Business calculations');
        $table->id();

        $table->unsignedBigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->comment('foreign key tables users');

       // $table->unsignedBigInteger('recipes_ID')->unsigned();
      //  $table->foreign('recipes_ID')->references('id')->on('recipes')->comment('foreign key tables users');
        $table->string('slug')->nullable()->unique()->comment('foreign key tables users');
        $table->string('thumbnail')->nullable()->comment('foreign key tables users');
        $table->string('path')->nullable()->comment('foreign key tables users');
        $table->string('size')->nullable()->comment('foreign key tables users');
        //$table->string('images')->nullable()->comment('foreign key tables users');
       // $table->string('alt')->nullable()->comment('foreign key tables users');
        $table->timestamps();
    });

Schema::create('recipes', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->charset = 'utf8mb4';
        $table->collation = 'utf8mb4_unicode_ci';
        //$table->comment('Business calculations');
        $table->id();

        $table->unsignedBigInteger('user_ID')->unsigned();
        $table->foreign('user_ID')->references('id')->on('users')->comment('foreign key tables users');



        $table->unsignedBigInteger('cuisines_id')->unsigned();
        $table->foreign('cuisines_id')->references('id')->on('cuisines')->comment('foreign key tables cuisines');

        $table->unsignedBigInteger('thumbnail_id')->unsigned();
        $table->foreign('thumbnail_id')->references('id')->on('thumbnails')->comment('foreign key tables photos');

        $table->unsignedBigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->comment('foreign key tables categories');

        $table->string('title')->nullable()->comment('foreign key tables users');
        $table->string('slug')->nullable()->comment('foreign key tables users');
        $table->text('dsescription')->nullable()->comment('foreign key tables users');
        $table->string('youtubevideo')->nullable()->comment('foreign key tables users');
        $table->string('method')->nullable()->comment('foreign key tables users');
        $table->string('difficlty')->nullable()->comment('foreign key tables users');
        $table->string('preptime')->nullable()->comment('foreign key tables users');
        $table->string('cooktime')->nullable()->comment('foreign key tables users');
        $table->string('total')->nullable()->comment('foreign key tables users');
        $table->string('servings')->nullable()->comment('foreign key tables users');
        $table->string('yield')->nullable()->comment('foreign key tables users');
        $table->text('ingredients')->nullable()->comment('foreign key tables users');
        $table->text('directions')->nullable()->comment('foreign key tables users');
        $table->text('nutritionFacts')->nullable()->comment('foreign key tables users');
        $table->timestamps();
    });

public function store(StorerecipesRequest $request)
   {


       $thumbnails =new thumbnails;

       if ($request->hasFile('thumbnails')) {
           $name = $request->file('thumbnails')->getClientOriginalName();
           $size = $request->file('thumbnails')->getSize();
           $path = $request->file('thumbnails')->storeAs('public/Recipes/thumbnails', $name);
       }

       $thumbnails = thumbnails::create([

            [ 'thumbnails' => $request->$name],
            [ 'path' => $request->$path ],
            [ 'size' => $request->$size ]
       ]);

       $recipes = new Recipes;

       $recipes = recipes::create([
           [ 'cuisines_id' => $request->cuisines_id ],
           [ 'category_id' => $request->category_id ],
           [ 'thumbnail_id' => $request->thumbnail_id ],
           [ 'name' => $request->name ],
           [ 'slug' => $request->slug ],
           [ 'dsescription' => $request->dsescription ],
           [ 'file' => $request->file ],
           [ 'youtubevideo' => $request->youtubevideo ],
           [ 'method' => $request->method ],
           [ 'difficlty' => $request->difficlty ],
           [ 'preptime' => $request->preptime ],
           [ 'cooktime' => $request->cooktime ],
           [ 'total' => $request->total ],
           [ 'servings' => $request->servings ],
           [ 'yield' => $request->yield ],
           [ 'ingredients' => $request->ingredients ],
           [ 'directions' => $request->directions ],
           [ 'nutritionFacts' => $request->nutritionFacts ],
       ]);

       $recipes->save();



       return redirect()->route('Recipes.show')->with('success', 'Recipes destroy successfully.');
   }


ErrorException
Undefined variable: name
[ 'thumbnails' => $request->$name],

我为我的写作差而深表歉意,并感谢您的帮助 谢谢

how i will create data insert into Different tow tables ?
Dear All Developer
how i will create data insert into Different tow tables (thumbnails - recipes ) in function store RecipesController, and i have Relationships with tables thumbnail_id foreign keys.
tables thumbnails :

Schema::create('thumbnails', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->charset = 'utf8mb4';
        $table->collation = 'utf8mb4_unicode_ci';
        //$table->comment('Business calculations');
        $table->id();

        $table->unsignedBigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->comment('foreign key tables users');

       // $table->unsignedBigInteger('recipes_ID')->unsigned();
      //  $table->foreign('recipes_ID')->references('id')->on('recipes')->comment('foreign key tables users');
        $table->string('slug')->nullable()->unique()->comment('foreign key tables users');
        $table->string('thumbnail')->nullable()->comment('foreign key tables users');
        $table->string('path')->nullable()->comment('foreign key tables users');
        $table->string('size')->nullable()->comment('foreign key tables users');
        //$table->string('images')->nullable()->comment('foreign key tables users');
       // $table->string('alt')->nullable()->comment('foreign key tables users');
        $table->timestamps();
    });

Schema::create('recipes', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->charset = 'utf8mb4';
        $table->collation = 'utf8mb4_unicode_ci';
        //$table->comment('Business calculations');
        $table->id();

        $table->unsignedBigInteger('user_ID')->unsigned();
        $table->foreign('user_ID')->references('id')->on('users')->comment('foreign key tables users');



        $table->unsignedBigInteger('cuisines_id')->unsigned();
        $table->foreign('cuisines_id')->references('id')->on('cuisines')->comment('foreign key tables cuisines');

        $table->unsignedBigInteger('thumbnail_id')->unsigned();
        $table->foreign('thumbnail_id')->references('id')->on('thumbnails')->comment('foreign key tables photos');

        $table->unsignedBigInteger('category_id')->unsigned();
        $table->foreign('category_id')->references('id')->on('categories')->comment('foreign key tables categories');

        $table->string('title')->nullable()->comment('foreign key tables users');
        $table->string('slug')->nullable()->comment('foreign key tables users');
        $table->text('dsescription')->nullable()->comment('foreign key tables users');
        $table->string('youtubevideo')->nullable()->comment('foreign key tables users');
        $table->string('method')->nullable()->comment('foreign key tables users');
        $table->string('difficlty')->nullable()->comment('foreign key tables users');
        $table->string('preptime')->nullable()->comment('foreign key tables users');
        $table->string('cooktime')->nullable()->comment('foreign key tables users');
        $table->string('total')->nullable()->comment('foreign key tables users');
        $table->string('servings')->nullable()->comment('foreign key tables users');
        $table->string('yield')->nullable()->comment('foreign key tables users');
        $table->text('ingredients')->nullable()->comment('foreign key tables users');
        $table->text('directions')->nullable()->comment('foreign key tables users');
        $table->text('nutritionFacts')->nullable()->comment('foreign key tables users');
        $table->timestamps();
    });

public function store(StorerecipesRequest $request)
   {


       $thumbnails =new thumbnails;

       if ($request->hasFile('thumbnails')) {
           $name = $request->file('thumbnails')->getClientOriginalName();
           $size = $request->file('thumbnails')->getSize();
           $path = $request->file('thumbnails')->storeAs('public/Recipes/thumbnails', $name);
       }

       $thumbnails = thumbnails::create([

            [ 'thumbnails' => $request->$name],
            [ 'path' => $request->$path ],
            [ 'size' => $request->$size ]
       ]);

       $recipes = new Recipes;

       $recipes = recipes::create([
           [ 'cuisines_id' => $request->cuisines_id ],
           [ 'category_id' => $request->category_id ],
           [ 'thumbnail_id' => $request->thumbnail_id ],
           [ 'name' => $request->name ],
           [ 'slug' => $request->slug ],
           [ 'dsescription' => $request->dsescription ],
           [ 'file' => $request->file ],
           [ 'youtubevideo' => $request->youtubevideo ],
           [ 'method' => $request->method ],
           [ 'difficlty' => $request->difficlty ],
           [ 'preptime' => $request->preptime ],
           [ 'cooktime' => $request->cooktime ],
           [ 'total' => $request->total ],
           [ 'servings' => $request->servings ],
           [ 'yield' => $request->yield ],
           [ 'ingredients' => $request->ingredients ],
           [ 'directions' => $request->directions ],
           [ 'nutritionFacts' => $request->nutritionFacts ],
       ]);

       $recipes->save();



       return redirect()->route('Recipes.show')->with('success', 'Recipes destroy successfully.');
   }


ErrorException
Undefined variable: name
[ 'thumbnails' => $request->$name],

I apologize for my poor writing and appreciate your help
thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文