尽管一切正常,Larvel Blade View仍未更新用户的数据库值

时间:2019-11-13 14:29:47

标签: php database laravel eloquent laravel-blade

我有一个刀片视图,用户在其中拥有不同的卡,这些卡具有不同的值(从1到7)。

我已经在可点击的div中放置了一个.svg,它通过参数将put请求发送到我的路由,我的路由接受接收到的数据并将其传递给我的控制器方法。我没有收到服务器错误或类似错误,但是我的值没有更新。

“ cards.blade.php”

<!-- Stored in resources/views/child.blade.php -->


@extends('layouts.app')


@section('title', 'Scrumpoker')



@section('content')

<div class="pull-right">

    <a href="{{ route('sessions.show', $currentRoom->id)}}" class="btn btn-light">Zurück</a>

</div>

<h3 align="center">Last updated: {{$currentRoom->updated_at->diffForHumans() ?? ''}}</h1>
    <h3 align="center">Room Number: {{$currentRoom->id}}</h1>

        @foreach ($currentUser as $user)
        <div align="left">
            <li>
                <!-- <h3><u>Userid</u> {{$user->id}}</h1> -->
                <h3><u>Username:</u> {{$user->name}}</h1>
                    <h3>{{$user->name}}'s estimation is: {{$user->userValue ?? ''}}</h1>
                        <h3>@if ($user->isAdmin === 1||$user->isAdmin !== null )
                            <strong>Scrummaster</strong>
                            @endif</h1>
                            <hr>

            </li>
        </div>
        @endforeach


                    <div class="centerDiv " onclick="document.forms['values'].submit();" style="cursor: pointer;">
                        <form action="{{route('sessions.values', $currentRoom->id)}}" name="values" method="post">
                            @csrf
                            @method('PUT')
                            <input type="number" value="1" name="userValue" hidden>
                            <img src="https://image.flaticon.com/icons/svg/188/188234.svg" height="50" width="50">
                        </form>
                    </div>

“ web.php”

Route::put('values/{id?}', 'SessionController@updateValues')
    ->name('sessions.values')
    ->middleware('auth');

“ SessionController@updateValues.php”

 public function updateValues($id, Request $request)

    {
        $currentUser = Auth::user();
        $currentRoom = Session::findOrFail($id);


        $currentUser->update([$request->userValue]);
        $currentRoom->touch();

        return redirect()->back()
            ->with('currentUser', $currentUser)
            ->with('currentRoom', $currentRoom);
    }

“ dd($ request,$ id)”

Request {#51 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure($guard = null) {#31 ▶}
  #routeResolver: Closure() {#236 ▶}
  +attributes: ParameterBag {#53 ▶}
  +request: ParameterBag {#52 ▼
    #parameters: array:3 [▼
      "_token" => "cKNFuU5GCLS7uL35OGq3nOGgLzOQD2dC7f96wy0S"
      "_method" => "PUT"
      "userValue" => "1"
    ]
  }
  +query: ParameterBag {#59 ▼
    #parameters: []
  }
  +server: ServerBag {#55 ▶}
  +files: FileBag {#56 ▶}
  +cookies: ParameterBag {#54 ▶}
  +headers: HeaderBag {#57 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/values/8"
  #requestUri: "/idk/public/values/8"
  #baseUrl: "/idk/public"
  #basePath: null
  #method: "PUT"
  #format: null
  #session: Store {#255 ▶}
  #locale: null
  #defaultLocale: "en"
  -isHostValid: true
  -isForwardedValid: true
  basePath: "/idk/public"
  format: "html"
}
"8"

1 个答案:

答案 0 :(得分:0)

update()方法不起作用,将我的SessionController @ updateValues更改为:

 public function updateValues($id, Request $request)

    {
        $currentUser = Auth::user();
        $currentRoom = Session::findOrFail($id);
        $updatedValue = $request->userValue;
        $currentUser->userValue = $updatedValue;
        $currentUser->save();
        $currentRoom->touch();


        return redirect()->back()
            ->with('currentUser', $currentUser)
            ->with('currentRoom', $currentRoom);
    }

现在它会更新我的用户特定值!