此表单不会发布到数据库

我是laravel和一般网络编程的新手。

我无法使此表格生效...顺便说一句,找不到一种可以使星号点击为数字的方法 对于验证请求,并且找不到将我需要提交的所有数据提交到所需路线的方法,我购买了一个学校项目的模板。

$ comic和$ review位于以下代码行的上方。

审查刀片

         <div class="tab-pane fade" id="addreview">
            <div class="review-add">
                <h4>{{$comic->comic_name}}</h4>
            </div>
            <div class="review-field-ratings">
                <span>La tua opinione <sup>*</sup></span>
                <div class="control">
                    <div class="single-control">
                        <span>Stars</span>
                        <div class="review-control-vote">
                            <a href=""><i class="fa fa-star"></i></a>
                            <a href=""="$i = 2"><i class="fa fa-star"></i></a>
                            <a href=""="$i = 3"><i class="fa fa-star"></i></a>
                            <a href=""="$i = 4"><i class="fa fa-star"></i></a>
                            <a href=""="$i = 5"><i class="fa fa-star"></i></a>
                        </div>
                    </div>
                </div>
            </div>
            <div class="review-form">
                <div class="single-form single-form-2">
                    <label for="review_title">Titolo <sup>*</sup></label>
                    <form>
                        <input id="review_title" type="text" class="form-control @error('review_title') is invalid @enderror" name="review_title"  value="{{ old('review_title') }}" required autocomplete="review_title" autofocus/>
                        @error('review_title')
                        <span class="invalid-feedback" role="alert">
                                                <strong>{{ $message }}</strong>
                                            </span>
                        @enderror
                    </form>
                </div>
                <div class="single1-form">
                    <label>Recensione <sup>*</sup></label>
                    <form>
                        <textarea name="review" cols="10" rows="10"></textarea>
                    </form>
                </div>
            </div>
            <div class="review-form-button">
                <form action>
                <a href="route('submitReview'.{{$comic->id}}">Invia recensione</a> 
                </form>
            </div>
        </div>

web.php

Route::post('/comic_detail/{id}','ReviewController@add')->name('submitReview');

ComicController

class ReviewController extends Controller
{
    public function add(Request $request,$id){
        $now = Carbon::now();
        $request->validate([
            'review_title' => ['required','max:20','min:3'],
            'review_text' =>['required', 'max:255','min:40'],
            'stars' => ['required','max:5','min:1'],
        ]);
        $user = \Illuminate\Support\Facades\Auth::user();
        $comic = Comic::where('id','=',$id);
        $review = new Review;
        $review->user_id = \Illuminate\Support\Facades\Auth::user()->id;
        $review->comic_id = $id;
        $review->review_title = $request->review_title;
        $review->review_text = $request->review_text;
        $review->stars = $request->stars;

        $data=array(
            'user_id'=> $review->user_id,
            'review_title'=> $review->review_title,
            'review_text'=> $review->review_text,
            'stars'=> $review->stars,
        );

        DB::table('reviews')->insert($data);


        return redirect('comic_detail/$id')
            ->with(compact('comic'));
    }

My form

评论
  • siusto
    siusto 回复

    Laravel POST路由受VerifyCsrfToken中间件的保护,因此您必须将令牌添加到表单中才能起作用。

    只需添加:

    {{ csrf_field() }}
    

    在您的任何地方,这应该可以解决问题。

    您还需要将方法添加到您的

    <form method="post">