Laravel页面错误 - 在每页顶部打印1

时间:2017-06-02 02:38:33

标签: php laravel request laravel-5.4

我正在使用具有普通视图和控制器的Laravel 5.4。

在我的web.php中我有以下路线:

Route::get('/quiz', 'QuizController@quiz');
Route::post('quiz/submit', array('uses' => 'QuizController@check'));

当我开始编写 Check()功能

时,一切正常
public function check(Request $request)
    {  

        $answers = array_flatten($request->except('_token'));
        $quiz =  config('enums.quiz');
        $correct = [];
        $result = [];
        foreach ($quiz as $key => $value) {
             foreach ($value as $key => $val) {
                 if ($val == 1) {
                    array_push($correct,  $key );
                 }
             }
        }
        foreach ($answers as $key => $value) {
            if ($correct[$key] == $value ) {
                $result[$value] = 1;
            }else {
                $result[$value] = 0;
            }
        }
        $request->session()->flash('results', $result);
        redirect('/quiz');
    }

和quiz.blade.php

@extends('layouts.app')

@section('content')
<div class="panel panel-default">
    <div class="panel-heading">
        Quiz
    </div>
    <div class="panel-body">


        {!!  Form::open(array('id'=> 'updateForm', 'style'=>'margin-bottom:10px;' ,"class"=>"form-horizontal" , "ng-app"=>"userform",   'url' => array('quiz/submit'))) !!}
        <ol type="1">
            @foreach ($questions as $question => $answers)
            {{-- loop throgh each question --}}
            <li class="question">
                <h4>
                    <strong>
                        {{ $question }}
                    </strong>
                </h4>
                <ol type="a">
                    @foreach ($answers as $answer => $isCorrect)
                    {{-- looping answers  of the question --}}                       

                    <li class="answer ">
                        <input name="answer_{{ $loop->parent->index }}" required="" type="radio"  value="{{ $answer }}">
                        {{ $answer }}
                    </input>
                </li>
                @endforeach
            </ol>
        </li>
        @endforeach
    </ol>

    <button class="btn btn-ok btn-default text-uppercase pull-right">Clear Answers</button>
    <span style="margin: 5px;" class="pull-right"> </span>
    {!! Form::submit('Submit Quiz', array('id'=>'btn_submit', 'class' => 'btn btn-ok btn-primary text-uppercase pull-right ' )) !!} 
    {!! Form::close() !!}

</div>
</div>
@endsection

然后突然它开始在每页的顶部打印 1 。即使我试图清除编译和清除会话,但仍然会产生问题。

php artisan clear-compiled
1The compiled services file has been removed.  

在每页的顶部打印相同的1,因此停止登录请求或任何其他页面请求。

提前致谢

2 个答案:

答案 0 :(得分:1)

如果你得到&#34; 1&#34;显示在每个页面的顶部...也就是说,包括在&#39; / quiz&#39;未返回的页面的顶部,以及&#34; 1&#34;正在您的“内容”中显示Bootstrap面板上方来自quiz.blade.php的部分...然后我的第一个猜测是你无意中改变了你的layouts.app刀片文件中的内容。检查那里。希望这会有所帮助。

答案 1 :(得分:1)

检查config文件夹php文件。在1其中一个php文件之前应该有<?php