在生产服务器上找不到错误类'App \ Http \ Controllers \ Input'

时间:2016-05-13 07:32:11

标签: html laravel

我在控制器的开头声明了use Illuminate\Support\Facades\Input;所以我不确定它为什么会抛出这个错误。我无法很好地测试这个,因为表单只能在生产服务器上运行,而不能在我的开发服务器上运行。

这是控制器

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Validator;
use Redirect;
use Mail;

use App\Http\Requests;

class contact extends controller
{
    // This function will show the view
    public function showForm()
    {
        return view('pages.contact');
    }

    public function handleFormPost()
    {
        $input = Input::only('name', 'email', 'msg');

        $validator = Validator::make($input,
            array(
                'name' => 'required',
                'email' => 'required|email',
                'msg' => 'required',
            )
        );

        if ($validator->fails())
        {
            return Redirect::to('contact')->with('errors', $validator->messages());
        } else { // the validation has not failed, it has passed


            // Send the email with the contactemail view, the user input
            Mail::send('contactemail', $input, function($message)
            {
                $message->from('idocompscihw@gmail.com', 'Your Name');

                $message->to('idocompscihw@gmail.com');
            });

            // Specify a route to go to after the message is sent to provide the user feedback
            return Redirect::to('thanks');
        }

    }
}

这是表格

<div class="container">
    <h1>A basic contact form</h1>
    <form id="contact" method="post" class="form" role="form">

        @if(Session::has('errors'))
            <div class="alert alert-warning">
                @foreach(Session::get('errors')->all() as $error_message)
                    <p>{{ $error_message }}</p>
                @endforeach
            </div>
        @endif

        <div class="row">
            <div class="col-xs-6 col-md-6 form-group">
                <input type="hidden" name="_token" value="{{ csrf_token() }}">
                <input class="form-control" id="name" name="name" placeholder="Name" type="text"autofocus="">
            </div>
            <div class="col-xs-6 col-md-6 form-group">
                <input class="form-control" id="email" name="email" placeholder="Email" type="text">
            </div>
        </div>
        <textarea class="form-control" id="message" name="msg" placeholder="Message" rows="5"></textarea>
        <br>
        <div class="row">
            <div class="col-xs-12 col-md-12 form-group">
                <button class="btn btn-primary pull-right" type="submit">Submit</button>
            </div>
        </div>
    </form>
</div>

任何帮助将不胜感激!谢谢!

2 个答案:

答案 0 :(得分:1)

Laravel 5将输入移动到请求中。

https://laravel.com/docs/5.2/requests#retrieving-input

将请求注入函数:

public function handleFormPost(Request $request) {
    $input = $request->only('whatever');

或使用请求外观(文件顶部需要use Request;):

public function handleFormPost() {
    $input = Request::only('whatever');

答案 1 :(得分:0)

几个解决方案

试试这个:

$input = \Input::only('name', 'email', 'msg');

或尝试更改此内容:

use Illuminate\Support\Facades\Input;

到此:

use Input;