我无法将数据存储到数据库

时间:2019-05-15 12:13:59

标签: laravel

我无法存储数据,没有错误,我尝试过在表单中​​将名称更改为id的事情,但是它并没有改变任何内容。

这是我的观点,不是全部,但是几乎每个选择都是这样

<form method="POST" action="{{ action('MatchController@store') }}">

    <select class="col-sm-2 form-control" name="users1" required>

      @foreach($users1 as $users1)
        @if ($users1->id == 0 or $users1->id == Auth::user()->id);
        @else
        <option selected value="{{$users1->nick}}">{{$users1->nick}}  </option> 

        @endif
      @endforeach

    </select>

<textarea rows="4" cols="50" class=" form-control" name="text" form="usrform">Deporte, condiciones, reglas, puntuación...</textarea><hr>
</form>
<button type="submit" class="btn btn-primary">{{ __('Enviar') }}</button>

这是我的控制人

public function store(Request $request)
    {

        $this->validate($request, [

            'users1' => 'required',
            'text' => 'required',

            ]);

            $vs = new Vs;
            $vs->users1 = $request->input('users1');
            $vs->text = $request->input('text');
            $vs->save();

            return redirect('/place');
    }

3 个答案:

答案 0 :(得分:0)

您没有在表单中添加{{ csrf_field() }}字段。

这是带有{{ csrf_field() }}字段的表单。你可以试试吗?

 <form method="POST" action="{{ action('MatchController@store') }}">
    {{ csrf_field() }}
        <select class="col-sm-2 form-control" name="users1" required>

          @foreach($users1 as $users1)
            @if ($users1->id == 0 or $users1->id == Auth::user()->id);
            @else
            <option selected value="{{$users1->nick}}">{{$users1->nick}}  </option> 

            @endif
          @endforeach

        </select>

    <textarea rows="4" cols="50" class=" form-control" name="text" form="usrform">Deporte, condiciones, reglas, puntuación...</textarea><hr>
    <button type="submit" class="btn btn-primary">{{ __('Enviar') }}</button>  
</form>

答案 1 :(得分:0)

您未在表单中使用csrf令牌,可以使用此

    <form method="POST" action="{{ action('MatchController@store') }}">
 <input type="hidden" name="_token" value="{{ csrf_token() }}" />
<select class="col-sm-2 form-control" name="users1" required>

  @foreach($users1 as $users1)
    @if ($users1->id == 0 or $users1->id == Auth::user()->id);
    @else
    <option selected value="{{$users1->nick}}">{{$users1->nick}}  </option> 

    @endif
  @endforeach

</select>

答案 2 :(得分:0)

在刀片文件中:

int main(void) {
    float tr[3][9], distances[3][3], points[3][3];
    float pointx, pointy, pointz, tAx, tAy, tAz, tBx, tBy, tBz, tCx, tCy, tCz;
    float A, B, C, D, min = 0;
    int i, j;

    for (i = 0; i < 3; i++) {
        printf("Enter the coordinates of %d point:", i + 1);
        for (j = 0; j < 3; j++)
            scanf("%f", &points[i][j]);
    }

    for (i = 0; i < 3; i++) {
        printf("Enter the coordinates of %d triangle:", i + 1);
        for (j = 0; j < 9; j++)
            scanf("%f", &tr[i][j]);
    }

    for (i = 0; i < 3; i++) {
        for (j = 0; j < 3; j++) {
            pointx = points[j][0], pointy = points[j][1], pointz = points[j][2];

            tAx = tr[i][0], tAy = tr[i][1], tAz = tr[i][2], tBx = tr[i][3], tBy = tr[i][4], tBz = tr[i][5], tCx = tr[i][6], tCy = tr[i][7], tCz = tr[i][8];
            A = tAy * (tBz - tCz) + tBy * (tCz - tAz) + tCy * (tAz - tBz);
            B = tAx * (tCz - tBz) + tBx * (tAz - tCz) + tCx * (tBz - tAz);
            C = tAx * (tBy - tCy) + tBx * (tCy - tAy) + tCx * (tAy - tBy);
            D = -A * tAx - B * tAy - C * tAz;

            if (A == 0 && B == 0 && C == 0) {
                printf("\nCannot create a plane equation for given points. Verify that the data entered is correct.\n");
                return -1;
            } else
                distances[i][j] =
                        fabs(A * pointx + B * pointy + C * pointz + D) / sqrt(pow(A, 2) + pow(B, 2) + pow(C, 2));;
        }
    }

    return 0;

}

在控制器中:

<form method="POST" action="{{ action('MatchController@store') }}">

    @csrf

    <select class="col-sm-2 form-control" name="users1" required>

        @foreach($users1 as $users1)
            @if ($users1->id == 0 or $users1->id == Auth::user()->id);
            @else
                <option selected value="{{$users1->nick}}">{{$users1->nick}}  </option> 
            @endif          
        @endforeach

    </select>

    <textarea rows="4" cols="50" class=" form-control" name="text" form="usrform">Deporte, condiciones, reglas, puntuación...</textarea><hr>

    <button type="submit" class="btn btn-primary">{{ __('Enviar') }}</button>
</form>