2016-05-13 60 views
-2

我在控制器的開頭聲明瞭use Illuminate\Support\Facades\Input;,所以我不確定它爲什麼會拋出這個錯誤。我無法對此進行很好的測試,因爲表單只能在生產服務器上運行,而不能在我的開發服務器上運行。在生產服務器上找不到錯誤類'App Http Controllers 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('[email protected]', 'Your Name'); 

       $message->to('[email protected]'); 
      }); 

      // 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

從另一個帳戶幾乎相同的職位?你應該編輯[這一個](http://stackoverflow.com/questions/37202978/fatal-error-class-app-http-controllers-input-not-found-when-sending-a-form),而不是張貼來自另一個帳戶的新問題。 –

+0

雖然這是一個不同的問題。對不起,如果我提交它很差。只是想解決這個問題,所以我可以睡 – user2238780

+0

@ user2238780看起來像同樣的問題,具有相同的答案。 – ceejayoz

回答

0

夫婦解決方案的

試試這個:

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

或者嘗試改變這一點:

use Illuminate\Support\Facades\Input; 

這樣:

use Input; 
1

Laravel 5移動輸入到請求。

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

無論是注入請求進入功能:

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

或使用Request門面(你會在文件的頂部需要一個use Request;):

public function handleFormPost() { 
    $input = Request::only('whatever'); 
相關問題