Skip to content

Instantly share code, notes, and snippets.

@vijayrami
Created April 14, 2020 18:09
Show Gist options
  • Save vijayrami/4e9c6dd2bb2e04a28cf229135f2e1f84 to your computer and use it in GitHub Desktop.
Save vijayrami/4e9c6dd2bb2e04a28cf229135f2e1f84 to your computer and use it in GitHub Desktop.
Create Custom request to apply validation
create file in App/Http/Requests/CsvImportRequest.php
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class CsvImportRequest 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 [
'csv_file' => 'required|mimes:xlsx,xls,csv'
];
}
}
in controller:
use App\Http\Requests\CsvImportRequest;
public function parseImport(CsvImportRequest $request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment