简体   繁体   English

此表单不会发布到数据库

[英]This form doesn't post to the database

I'm new to programming with laravel and with the web in general.我是使用laravel和 web 编程的新手。

I cannot make this form work... By the way I cannot find a way to make a star click as an number for the validate request and can't find a way to make all the data I need submitted to the route I need.我无法使此表单工作...顺便说一句,我找不到将星号单击作为验证请求的数字的方法,也找不到将所需的所有数据提交到所需路线的方法。 I bought the template for a school project.我买了一个学校项目的模板。

$comic and $review are present above their following line of code. $comic 和 $review 出现在它们下面的代码行之上。

Review Blade审查刀片

<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 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'));
    }
}

我的表格

I'm new to programming with laravel and with the web in general.我是使用laravel和 web 编程的新手。

I cannot make this form work... By the way I cannot find a way to make a star click as an number for the validate request and can't find a way to make all the data I need submitted to the route I need.我无法使此表单工作...顺便说一句,我找不到将星号单击作为验证请求的数字的方法,也找不到将所需的所有数据提交到所需路线的方法。 I bought the template for a school project.我买了一个学校项目的模板。

$comic and $review are present above their following line of code. $comic 和 $review 出现在它们下面的代码行之上。

Review Blade审查刀片

<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 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'));
    }
}

我的表格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM