Reputation: 77
I have a blade view, where an user has different cards with different values (range from one to seven).
I've put a .svg inside a clickable div, that sends the put request to my route with paramters, my route accepts the received data and pass it to my controller method. I get no server error or similar, but my value is not updating however.
"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');
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"
Upvotes: 1
Views: 624
Reputation: 77
update() method was somehow not working, changed my SessionController@updateValues to:
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);
}
Now it does update my user specific values!
Upvotes: 0