blue-twilight/app/Http/Requests/StoreServiceRequest.php

75 lines
2.1 KiB
PHP

<?php
namespace App\Http\Requests;
use App\ExternalService;
use Illuminate\Foundation\Http\FormRequest;
class StoreServiceRequest 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()
{
$result = [];
switch ($this->method())
{
case 'POST':
$result = [
'name' => 'required|unique:external_services|max:255',
'service_type' => 'required|max:255',
];
switch ($this->get('service_type'))
{
case ExternalService::DROPBOX:
case ExternalService::FACEBOOK:
case ExternalService::GOOGLE:
case ExternalService::TWITTER:
// Standard OAuth services
$result['app_id'] = 'sometimes|required';
$result['app_secret'] = 'sometimes|required';
break;
}
break;
case 'PATCH':
case 'PUT':
$serviceId = intval($this->segment(3));
$service = ExternalService::find($serviceId);
$result = [
'name' => 'required|max:255|unique:external_services,name,' . $serviceId
];
switch ($service->service_type)
{
case ExternalService::DROPBOX:
case ExternalService::FACEBOOK:
case ExternalService::GOOGLE:
case ExternalService::TWITTER:
// Standard OAuth services
$result['app_id'] = 'sometimes|required';
$result['app_secret'] = 'sometimes|required';
break;
}
break;
}
return $result;
}
}