55 lines
1.4 KiB
PHP
55 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Requests;
|
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
|
|
|
class UpdateCityRequest extends FormRequest
|
|
{
|
|
/**
|
|
* Determine if the user is authorized to make this request.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function authorize()
|
|
{
|
|
$user = $this->user();
|
|
|
|
return $user != null && $user->tokenCan('update');
|
|
}
|
|
|
|
/**
|
|
* Get the validation rules that apply to the request.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function rules()
|
|
{
|
|
|
|
|
|
if ($this->method() == 'PUT') {
|
|
return [
|
|
'locationName' => ['required'],
|
|
'locationCountry' => ['required'],
|
|
'currentTemperature' => ['required'],
|
|
'weatherIcon' => ['required'],
|
|
'weatherDescription' => ['required'],
|
|
'windSpeed' => ['required'],
|
|
'localtimeEpoch' => ['required'],
|
|
];
|
|
}
|
|
|
|
}
|
|
|
|
protected function prepareForValidation() {
|
|
$this->merge([
|
|
'location_name' => $this->locationName,
|
|
'location_country' => $this->locationCountry,
|
|
'current_temperature' => $this->currentTemperature,
|
|
'weather_icon' => $this->weatherIcon,
|
|
'weather_description' => $this->weatherDescription,
|
|
'wind_speed' => $this->wind_speed,
|
|
'localtime_epoch' => $this->localtime_epoch
|
|
]);
|
|
}
|
|
} |