我试图从Laravel应用程序发送一封填写表格的电子邮件。
当您点击提交时,会抛出上述错误:
致命错误:Class' App \ Http \ Controllers \ Input'找不到
不知道为什么我没有,也不知道我需要一个输入控制器,或者我会放入它。
以下是控制器的内容:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
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');
}
}
}
以下是论坛的视图(基于bootstrap):
<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>
答案 0 :(得分:6)
在contact.php控制器中使用它 -
use Illuminate\Support\Facades\Input;
您的错误将得到修复。感谢。
答案 1 :(得分:2)
Input ::被Request ::替换。而不是
lapply(1:5, function(b, a, ...) fun(a = a, b = b, ...), a = 4)
使用它:
$input = Input::only('name', 'email', 'msg');
如果您收到有关“不应静态使用”的错误,请将其添加到文件顶部
$input = Request::only('name', 'email', 'msg');
如果你已有这一行:
use Request;
删除它,因为在一个文件中不能有两个具有相同名称的类
答案 2 :(得分:1)
public function handleFormPost(Request $request)
{
$name = $request->get('name');
$email = $request->get('email');
$msg = $request->get('msg');
}
OR
public function handleFormPost(Request $request)
{
$input = $request->all();
}
答案 3 :(得分:0)
你不使用输入试试这个:
use Input;
将它放在像
这样的名称空间声明之后<?php
namespace App\Http\Controllers;
use Input;
...
?>