Files
freeu-project/app/Http/Requests/ContactUsRequest.php
Ritikesh yadav c661166e1d first commit
2024-03-28 14:52:40 +05:30

77 lines
1.8 KiB
PHP

<?php
namespace App\Http\Requests;
use Stevebauman\Location\Facades\Location;
use Illuminate\Foundation\Http\FormRequest;
class ContactUsRequest 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()
{
return [
'name' => 'required',
'mobile_number' => 'required|numeric|digits:10',
'email' => 'required|email',
'subject' => 'required',
'message' => 'required',
'type' => 'required',
'representative_name' => 'nullable',
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array<string, string>
*/
public function messages()
{
return [
'required' => 'The :attribute field is required.',
'numeric' => 'The :attribute field must be in digits',
'digits' => 'The :attribute field must have 10 digits',
];
}
public function validated()
{
if ($position = Location::get()) {
$ipAddress = $position->ip;
$location = $position->countryName;
}
// dd(auth('sanctum')->check());
$status = false;
if(auth('sanctum')->check())
{
$status = true;
}else if(auth()->guard('users')->check())
{
$status = true;
}
return array_merge(parent::validated(), [
'location' => $location ?? null,
'ip_address' => $ipAddress ?? null,
// 'page' => $user_id == true ? '1' : '0',
'page' => $status,
]);
}
}