Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
In this tutorial I will explain a complete guide of Laravel form validation, As many of you already know there are many ways to validate requests in Laravel, Handling request validation is very crucial part of any application. Laravel has some great feature which deals with this very well.
php artisan make:request StudentValRequest
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StudentValRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'student_name' => 'required',
'student_email' => 'required',
'student_address' => 'required',
];
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\StudentValRequest;
use PDF;
use Session;
use App\ExportPdfs;
class ExportPdfController extends Controller
{
public function store(StudentValRequest $request)
{
$data = new ExportPdfs();
$data->student_name = $request->student_name;
$data->student_email = $request->student_email;
$data->student_address = $request->student_address;
$data->save();
return redirect()->route('pdf.list')->with('flash_message_success','Record added Successfully');
}
}
A brief introduction about laravel validation : click here
Read also : How to quickly generate data using faker and tinker ?