Files
Global-Jain/app/Http/Requests/Api/Post/StorePostRequest.php
2025-11-05 10:37:10 +05:30

60 lines
1.6 KiB
PHP

<?php
namespace App\Http\Requests\Api\Post;
use App\Constant\Constant;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
class StorePostRequest 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(Request $request)
{
$data = $request->all();
$array = [
'privacy' => 'required',
'images' => 'array|required_without:description',
'images.*' => 'image|mimes:jpeg,png,jpg,gif|max:15360',
'description' => 'required_without:images',
'category_id' => 'required|exists:categories,id',
'type' => 'nullable|in:1,2,3',
'type_id' => 'nullable|exists:users,id',
];
$name = Route::currentRouteName();
if ($name == 'api.post.sant.store') {
$array['type_id'] = 'required|exists:sants,id';
$array['type'] = 'required|in:2';
}
if ($data['type'] == Constant::POST_TYPE_SANT) {
$array['type_id'] = 'required|exists:sants,id';
$array['type'] = 'required|in:2';
}
if ($data['type'] == Constant::POST_TYPE_SANGH) {
$array['type_id'] = 'required|exists:sanghs,id';
$array['type'] = 'required|in:3';
}
return $array;
}
}