init
This commit is contained in:
50
app/Http/Requests/StoreCityRequest.php
Normal file
50
app/Http/Requests/StoreCityRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreCityRequest 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('create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
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
|
||||
]);
|
||||
}
|
||||
}
|
||||
55
app/Http/Requests/UpdateCityRequest.php
Normal file
55
app/Http/Requests/UpdateCityRequest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?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
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user