1
是否有任何方式自動顯示錯誤信息?就像它在CodeIgniter中一樣? 我有一個接觸的形式,如果它的驗證錯誤,我做:Laravel聯繫人模板錯誤
return Redirect::to('/support/contact')
->with('message', 'Feedback must contain more than 5 characters. Try Again.');
我的規則,我的領域:
$rules = array (
'first_name' => 'required',
'email' => 'required|email',
'message' => 'required|min:5'
);
這是任何方式,根據我的領域,使汽車的消息?
我的控制器:
<?php
namespace App\Http\Controllers;
use Input;
use Illuminate\Http\Request;
use Validator;
use Mail;
use Redirect;
class ContactController extends Controller
{
public function getContactUsForm(){
$data = \Input::all();
$rules = array (
'first_name' => 'required',
'email' => 'required|email',
'message' => 'required|min:5'
);
$validator = Validator::make ($data, $rules);
if ($validator -> passes()){
Mail::send('emails.contact', $data, function($bodyMessage) use ($data)
{
$bodyMessage->from($data['email'] , $data['first_name']);
$bodyMessage->to('[email protected]', 'He')->subject(' Contact Form');
});
return Redirect::to('/support/contact')
->with('message', 'Your message has been sent. Thank You!');
}else{
return Redirect::to('/support/contact')
->with('message', 'Feedback must contain more than 5 characters. Try Again.');
}
}
}
是的,但您如何定義郵件取決於您如何應用規則。你使用控制器'$ this-> validate()'方法,你使用表單請求驗證還是手動創建你自己的驗證器實例?請顯示更多代碼。 – jfadich
@jfadich發佈了我的控制器代碼 – Rost