首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我没有把数据提交给数据库,我遍历了代码,每件事都很好,找不到问题,我使用的是Laravel和顺风

我没有把数据提交给数据库,我遍历了代码,每件事都很好,找不到问题,我使用的是Laravel和顺风
EN

Stack Overflow用户
提问于 2022-08-12 22:03:57
回答 1查看 34关注 0票数 -3

这是我的控制器,现在我使用两个方法创建和存储,我检查来自PHP的数据提交,我的管理员,我看了大量的vides和文档,但没有任何帮助,我在代码中遍历了几十遍,但是没有找到任何能帮助解决问题的方法,没有什么问题,没有出现错误,但是仍然没有将表单加在一起,它也会在我指定的存储方法中重定向我。

代码语言:javascript
复制
<?php

namespace App\Http\Controllers;

use App\Models\generalForm;
use Illuminate\Http\Request;

class GeneralFormController extends Controller
{
   
    public function index()
    {
    //
    }

    
    public function create()
    {
     return view('getStarted');
    }

 
    public function store(Request $request)
    {
        $request->validate([
            'startup_name' => 'required',
            'first_name' => 'required|string',
            'last_name' => 'required|string',
            'email' => 'required|email',
            'mobile_number' => 'required|numeric|min:10|max:10',
            'Adress' => 'required',
            'Services[]' => 'required',
            'Needs[]' => 'required',
            'project_phase' => 'required',
     ]);

    
        dd($request->all());
        $input= generalForm::create([
            'startup_name' => $request->startup_name,
            'first_name' => $request->first_name,
            'last_name' => $request->last_name,
            'email' => $request->email,
            'mobile_number' => $request->mobile_number,
            'Address' => $request->Address,
            'Services[]' => implode(",",$request->Services[]),
            'Needs[]' => implode(",",$request->Needs[]),
            'project_phase' => $request->project_phase,

        ]); 

        return redirect()->back();
    }


    public function show(generalForm $generalForm)
    {
        //
    }

  
    public function edit(generalForm $generalForm)
    {
        //
    }

 
    public function update(Request $request, generalForm $generalForm)
    {
        //
    }

  
    public function destroy(generalForm $generalForm)
    {
        //
    }
}
代码语言:javascript
复制
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('general_forms', function (Blueprint $table) {
            $table->id();
            $table->string('startup_name');
            $table->string('first_name');
            $table->string('last_name');
            $table->string('email');
            $table->string('mobile_number');
            $table->string('Address');
            $table->string('Services');
            $table->string('Needs');
            $table->string('project_phase');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('general_forms');
    }
};
代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="{{tailwindcss('css/app.css')}}" />

     <!--Services style-->
     <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Swiper/6.4.8/swiper-bundle.min.css"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

     <!--Services script-->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Swiper/6.4.8/swiper-bundle.min.js"></script>
  <script src="scripts.js"></script>

    <title>Get Started</title>
    @vite('resources/css/app.css')
    @vite('resources/js/script.js')
  </head>

  <body>
    <!-- Navbar -->
    <nav id="Home"class="relative container mx-auto px-6">
      <!-- Flex container -->
      <div class="flex items-center justify-between">
        <!-- Logo -->
        <div class="pt-2">
          <img class= "md:1/2 h-32 w-32" src="img/SniperLogo1.SVG" alt="" />
        </div>
      </div>

    
    </nav>
    
<!--
  This component uses @tailwindcss/forms

  yarn add @tailwindcss/forms
  npm install @tailwindcss/forms

  plugins: [require('@tailwindcss/forms')]
-->



<!---General info-->

<div class="max-w-screen-xl  px-4 mx-auto sm:px-6 lg:px-8 ">
  <div class="max-w-lg mx-auto">
    <h1 class="text-2xl font-bold text-center text-darkRed sm:text-3xl">Get started today</h1>

    <p class="max-w-md mx-auto mt-4 text-center text-gray-500">
    Every <a class="text-darkRed">Sniper</a> has A story , create yours now
    </p>

<form method="POST" action="{{ url('/store')}}"  enctype="multipart/form-data"  class="p-8 mt-6 mb-0 space-y-4 rounded-lg shadow-xl" >
       @csrf

      <div >
        <label for="startup_name" class="text-md font-medium">Startup-SMEs Name</label>
        <div class="relative mt-1">
          <input type="text" id="startup_name" name="startup_name" class="w-full p-4 pr-12 text-sm border-gray-200 rounded-lg shadow-sm" placeholder="Enter Startup-SMEs Name"/>
        </div>
      </div>

      <div >
        <label for="first_name" class="text-md font-medium">First Name</label>
        <div class="relative mt-1">
          <input type="text" id="first_name" name="first_name"  class="w-full p-4 pr-12 text-sm border-gray-200 rounded-lg shadow-sm" placeholder="Enter First Name"/>
        </div>
      </div>

      <div>
        <label for="last_name" class="text-md font-medium">Last Name</label>
        <div class="relative mt-1">
          <input type="text" id="last_name" name="last_name" class="w-full p-4 pr-12 text-sm border-gray-200 rounded-lg shadow-sm" placeholder="Enter Last Name"/>
        </div>
      </div>


      <div>
        <label for="email" class="text-md font-medium">Email</label>
        <div class="relative mt-1">
          <input type="email" id="email" name="email" class="w-full p-4 pr-12 text-sm border-gray-200 rounded-lg shadow-sm" placeholder="Enter email"/>

          <span class="absolute inset-y-0 inline-flex items-center right-4">
            <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 12a4 4 0 10-8 0 4 4 0 008 0zm0 0v1.5a2.5 2.5 0 005 0V12a9 9 0 10-9 9m4.5-1.206a8.959 8.959 0 01-4.5 1.207"/>
            </svg>
          </span>
        </div>
      </div>

      <div>
        <label for="mobile_number" class="text-md font-medium">Phone Number</label>
        <div class="relative mt-1">
          <input type="tel" id="mobile_number" name="mobile_number" class="w-full p-4 pr-12 text-sm border-gray-200 rounded-lg shadow-sm" placeholder="Enter Phone Number"/>
        </div>
      </div>

      <div>
        <label for="Address" class="text-md font-medium">Address</label>
        <div class="relative mt-1">
          <input type="text" id="Address" name="Address" class="w-full p-4 pr-12 text-sm border-gray-200 rounded-lg shadow-sm" placeholder="Enter Address"/>
        </div>
      </div>


           <!--- Services --->
    <div class="flex">
      <div>
       <label for="Services" class="text-md font-medium">Services</label>

      <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"  checked name="Services[]" value="MARKETING">
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]"  >MARKETING
      </label>
      </div>

     <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"  name="Services[]" value="BUSINESS MODEL">
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]" >BUSINESS MODEL
      </label>
     </div>

     <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox" name="Services[]" value="OPERATION">
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]" >OPERATION
      </label>
     </div>

     <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"   name="Services[]" value="FRASIIBILITY STUDY" >
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]" >FRASIIBILITY STUDY
      </label>
     </div>

     <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"  name="Services[]" value="TECHNOLOGY" >
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]" >TECHNOLOGY
      </label>
     </div>

     <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"  name="Services[]" value="FRANCHISE" >
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]" >FRANCHISE
      </label>
    </div>

    <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"   name="Services[]" value="FUNDING" >
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]" >FUNDING
      </label>
     </div>

     <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"   name="Services[]" value="Offices" >
      <label class="text-sm font-medium text-black dark:text-black" for="Services[]" >Offices
      </label>
     </div>

    </div>

  </div>


     <!--- NEEDS --->
   <div class="flex">
    <div>
     <label for="Needs" class="text-md font-medium">Needs</label>
      <div class="form-check">
        <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"  checked name="Needs[]" value="Consultation">
        <label class="form-check-label inline-block text-gray-800" for="Needs[]"  >Consultation
        </label>
     </div>

      <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"   name="Needs[]" value="Mentorship">
      <label class="form-check-label inline-block text-gray-800" for="Needs[]">Mentorship
      </label>
      </div>

      <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"  name="Needs[]" value="Knowledge">
      <label class="form-check-label inline-block text-gray-800" for="Needs[]" >Knowledge
      </label>
      </div>

      <div class="form-check">
      <input class="form-check-input appearance-none h-4 w-4 border border-gray-300 rounded-sm bg-white  mt-1 align-top bg-no-repeat bg-center bg-contain float-left mr-2  text-darkRed" type="checkbox"   name="Needs[]" value="Incubation"  >
      <label class="form-check-label inline-block text-gray-800" for="Needs[]" >Incubation
      </label>
      </div>
 
    </div>

   </div>



     <!--- Your project phase  --->

      <div>
        <label for="Address" class="text-md font-medium">Your project phase</label>
        <div class="relative mt-1">

        <div class="flex items-center mb-2">
        <input checked id="project_phase" type="radio" value="IDEA" name="project_phase" class="w-4 h-4 text-darkRed border-gray-300 bg-white">
    <label for="project_phase" class="ml-2 text-sm font-medium text-black dark:text-black">IDEA</label>
    </div>

  <div class="flex items-center mb-2">
    <input  id="project_phase" type="radio" value="FEASIBILITY STUDY" name="project_phase" class="w-4 h-4 text-darkRed border-gray-300 bg-white">
    <label for="project_phase" class="ml-2 text-sm font-medium text-black dark:text-black">FEASIBILITY STUDY</label>
   </div>

  <div class="flex items-center mb-2">
  <input id="project_phase" type="radio" value="PRESEED" name="project_phase" class="w-4 h-4 text-darkRed border-gray-300 bg-white">
    <label for="project_phase" class="ml-2 text-sm font-medium text-black dark:text-black">PRESEED</label>
  </div>

 <div class="flex items-center mb-2">
 <input id="project_phase" type="radio" value="SEED PHASE" name="project_phase" class="w-4 h-4 text-darkRed border-gray-300 bg-white">
    <label for="project_phase" class="ml-2 text-sm font-medium text-black dark:text-black">SEED PHASE</label>
 </div>

 <div class="flex items-center mb-2">
 <input id="project_phase" type="radio" value="ROUND A" name="project_phase" class="w-4 h-4 text-darkRed border-gray-300 bg-white">
    <label for="project_phase" class="ml-2 text-sm font-medium text-black dark:text-black">ROUND A</label>
 </div>

  <div class="flex items-center mb-2">
    <input id="project_phase" type="radio" value="SERIES B" name="project_phase" class="w-4 h-4 text-darkRed border-gray-300 bg-white">
    <label for="project_phase" class="ml-2 text-sm font-medium text-black dark:text-black">SERIES B</label>
  </div>

    </div>
      </div>


      <button type="submit" class="block w-full px-5 py-3 text-sm font-medium text-white bg-darkRed rounded-lg">
        SUBMIT
      </button>
</form>

  </div>
</div>

      

  </body>
</html>
代码语言:javascript
复制
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\journeyController;
use App\Http\Controllers\GeneralFormController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

/*Route::get('/', function () {
    return view('welcome');
});*/

Route::get('/journey', 'App\Http\Controllers\journeyController@sniperj');

Route::get('/Aboutus', 'App\Http\Controllers\AboutusController@sniperA');

Route::get('/', 'App\Http\Controllers\HomeController@sniperH');

Route::get('/getStarted', 'App\Http\Controllers\GeneralFormController@create');

Route::post('/store', 'App\Http\Controllers\GeneralFormController@store');

Route::get('/request', function () {
    return view('requestTable');
});

Route::get('/viewR', function () {
    return view('viewRequest');
});
EN

回答 1

Stack Overflow用户

发布于 2022-08-12 22:57:26

表单有多个错误。其主要原因是不显示验证错误。

然后在验证中需要一个名为Adress的字段,但它是表单名称中的Address

然后,您有一个讨厌的混合标题和小写名称,如emailAddress -保持一致(使用小写)

您的project_phase输入多次重复,但并不是通过向每个实例添加[]来将其表示为数组。

应该使用*语法(如'Services.*' => 'required', )验证数组字段,或者如果您只想检查是否存在服务数组,而不是检查每个元素,那么:'Services' => 'required',

在处理表单数据时,我做的第一件事就是转储请求,这样我就可以确切地看到我正在处理的是什么,检查所有字段名的拼写,以及它们包含我输入的值。

只有到那时,我才会继续进行验证。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73340166

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档