Created
November 16, 2015 10:20
-
-
Save stankusl/17ee799b51b86af707e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Requests; | |
use App\Http\Requests\Request; | |
use Illuminate\Support\Facades\Route; | |
class OfficeRequests extends Request | |
{ | |
/** | |
* 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() | |
{ | |
\Validator::extend('longitude', function($attribute, $value, $parameters) | |
{ | |
return preg_match('/^[-]?((((1[0-7][0-9])|([0-9]?[0-9]))\.(\d+))|180(\.0+)?)$/', $value); | |
}, 'The :attribute is not valid.'); | |
\Validator::extend('latitude', function($attribute, $value, $parameters) | |
{ | |
return preg_match('/^[-]?(([0-8]?[0-9])\.(\d+))|(90(\.0+)?)$/', $value); | |
}, 'The :attribute is not valid.'); | |
if( Route::getCurrentRoute()->getPath() == 'office/create' ) | |
{ | |
return [ | |
'name' => 'required', | |
'address1' => 'required', | |
'city' => 'required', | |
'postcode' => 'required', | |
'telephone' => 'required', | |
'longitude' => 'required|longitude', | |
'latitude' => 'required|latitude', | |
'region' => 'required' | |
]; | |
} | |
if( Route::getCurrentRoute()->getPath() == 'office/edit/{id}' ) | |
{ | |
return [ | |
'name' => 'required', | |
'address1' => 'required', | |
'city' => 'required', | |
'postcode' => 'required', | |
'telephone' => 'required', | |
'longitude' => 'required|longitude', | |
'latitude' => 'required|latitude', | |
'region' => 'required' | |
]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Regex longitude and latitude validation class for Laravel 5.0+.