我目前有一个工作评论表,用户可以写一篇关于酒店的评论。到目前为止,它需要一个标题和正文,但我现在希望实施星级评级,以便用户选择一个评级并将其提交到我的数据库。我目前有用户可以提交标题和正文的代码,但是星级不会提交,也不会提交到我的数据库。谁能建议?
ReviewController.php
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required' ,
'body' => 'required' ,
'post_id' => 'required'
]);
$review = new Review;
$review->title = $request->input('title');
$review->body = $request->input('body');
$review->rating = $request->input('rating');
$review->post_id = $request['post_id'];
$review->save();
return redirect('/posts')->with('success', 'post created');
}
显示.blade.php
<h1>Reviews</h1>
@if(count($review) > 1)
@foreach($review as $reviews)
<div class= "well">
<h3><a href="/reviews/{{$reviews->title}}">{{$reviews->title}} </a>{{$reviews->rating}}</h3><small>{{$reviews->created_at}}</small><br>
<small>{{$reviews->body}}</small>
<br>
<br>
</div>
@endforeach
@else
</p>no posts found</p>
@endif
@endsection
Java脚本:
var count;
function starmark(item)
{
count=item.id[0];
sessionStorage.starRating = count;
var subid= item.id.substring(1);
for(var i=0;i<5;i++)
{
if(i<count)
{
document.getElementById((i+1)+subid).style.color="orange";
}
else
{
document.getElementById((i+1)+subid).style.color="black";
}
}
}
当我将其提交到我的数据库时,这些值显示为 NULL,但我希望它们的值介于 1-5 之间。
开心每一天1111