This commit is contained in:
mohanmd 2026-06-09 09:51:59 +05:30
parent 2c8fb9e757
commit 3b5a0d48ac
7 changed files with 185 additions and 132 deletions

View File

@ -170,13 +170,16 @@ public function verifyOtp(Request $request)
public function setupProfile(Request $request) public function setupProfile(Request $request)
{ {
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'phone' => 'required_without:email|nullable|string|max:50', 'phone' => 'required_without:email|nullable|string|max:50',
'email' => 'required_without:phone|nullable|email|max:255', 'email' => 'required_without:phone|nullable|email|max:255',
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'nationality' => 'required|string|max:100', 'nationality' => 'required|string|max:100',
'language' => 'nullable|string', 'language' => 'nullable|string',
'skills' => 'nullable|array', 'gender' => 'nullable|string|in:male,female,other',
'skills.*' => 'integer|exists:skills,id', 'live_in_out' => 'nullable|string|in:live_in,live_out',
'preferred_location' => 'nullable|string|max:255',
'skills' => 'nullable|array',
'skills.*' => 'integer|exists:skills,id',
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
@ -225,22 +228,25 @@ public function setupProfile(Request $request)
$worker = DB::transaction(function () use ($request, $email, $apiToken) { $worker = DB::transaction(function () use ($request, $email, $apiToken) {
$worker = Worker::create([ $worker = Worker::create([
'name' => $request->name, 'name' => $request->name,
'email' => $email, 'email' => $email,
'phone' => $request->phone ?? null, 'phone' => $request->phone ?? null,
'language' => $request->language ?? 'HI', // Default to Hindi if not selected 'language' => $request->language ?? 'HI', // Default to Hindi if not selected
'password' => Hash::make(Str::random(16)), // No password at this stage 'password' => Hash::make(Str::random(16)), // No password at this stage
'nationality' => $request->nationality, 'nationality' => $request->nationality,
'age' => 25, // Default — updated later in full profile 'gender' => $request->gender,
'salary' => 1500, // Default AED — updated later 'live_in_out' => $request->live_in_out,
'availability'=> 'Immediate', 'preferred_location' => $request->preferred_location,
'experience' => 'Not Specified', 'age' => 25, // Default — updated later in full profile
'religion' => 'Not Specified', 'salary' => 1500, // Default AED — updated later
'bio' => 'New worker on Migrant platform.', 'availability' => 'Immediate',
'category_id' => \App\Models\WorkerCategory::where('name', 'General Helper')->value('id') ?? (\App\Models\WorkerCategory::firstOrCreate(['name' => 'General Helper'])->id), 'experience' => 'Not Specified',
'verified' => false, 'religion' => 'Not Specified',
'status' => 'active', 'bio' => 'New worker on Migrant platform.',
'api_token' => $apiToken, 'category_id' => \App\Models\WorkerCategory::where('name', 'General Helper')->value('id') ?? (\App\Models\WorkerCategory::firstOrCreate(['name' => 'General Helper'])->id),
'verified' => false,
'status' => 'active',
'api_token' => $apiToken,
]); ]);
// Sync skills if provided // Sync skills if provided
@ -281,24 +287,26 @@ public function setupProfile(Request $request)
public function register(Request $request) public function register(Request $request)
{ {
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'phone' => 'required|string|max:50|unique:workers,phone', 'phone' => 'required|string|max:50|unique:workers,phone',
'salary' => 'required|numeric|min:0', 'salary' => 'required|numeric|min:0',
'password' => 'required|string|min:6', 'password' => 'required|string|min:6',
'passport_file' => 'required|file|mimes:jpeg,png,jpg,pdf|max:10240', 'passport_file' => 'required|file|mimes:jpeg,png,jpg,pdf|max:10240',
'skills' => 'nullable', 'skills' => 'nullable',
'visa_file' => 'nullable|file|mimes:jpeg,png,jpg,pdf|max:10240', 'visa_file' => 'nullable|file|mimes:jpeg,png,jpg,pdf|max:10240',
'language' => 'nullable|string', 'language' => 'nullable|string',
'nationality' => 'nullable|string|max:100', 'nationality' => 'nullable|string|max:100',
'age' => 'nullable|integer', 'age' => 'nullable|integer',
'experience' => 'nullable|string|max:100', 'experience' => 'nullable|string|max:100',
'in_country' => 'nullable', 'in_country' => 'nullable',
'visa_status' => 'nullable|string|max:100', 'visa_status' => 'nullable|string|max:100',
'preferred_job_type' => 'nullable|string|max:100', 'preferred_job_type' => 'nullable|string|max:100',
'live_in_out' => 'nullable|string|max:100', 'gender' => 'nullable|string|in:male,female,other',
'country' => 'nullable|string|max:100', 'live_in_out' => 'nullable|string|in:live_in,live_out',
'city' => 'nullable|string|max:100', 'preferred_location' => 'nullable|string|max:255',
'area' => 'nullable|string|max:100', 'country' => 'nullable|string|max:100',
'city' => 'nullable|string|max:100',
'area' => 'nullable|string|max:100',
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
@ -356,29 +364,31 @@ public function register(Request $request)
$result = DB::transaction(function () use ($request, $email, $skillsArray, $passportPath, $visaPath, $apiToken, $inCountry) { $result = DB::transaction(function () use ($request, $email, $skillsArray, $passportPath, $visaPath, $apiToken, $inCountry) {
$worker = Worker::create([ $worker = Worker::create([
'name' => $request->name, 'name' => $request->name,
'email' => $email, 'email' => $email,
'phone' => $request->phone, 'phone' => $request->phone,
'language' => $request->language ?? 'HI', 'language' => $request->language ?? 'HI',
'password' => Hash::make($request->password), 'password' => Hash::make($request->password),
'nationality' => $request->nationality ?? 'Not Specified', 'nationality' => $request->nationality ?? 'Not Specified',
'age' => $request->age ?? 25, 'gender' => $request->gender,
'salary' => $request->salary, 'live_in_out' => $request->live_in_out,
'availability'=> 'Immediate', 'preferred_location' => $request->preferred_location,
'experience' => $request->experience ?? 'Not Specified', 'age' => $request->age ?? 25,
'religion' => 'Not Specified', 'salary' => $request->salary,
'bio' => 'Hardworking and reliable General Helper available for immediate hire.', 'availability' => 'Immediate',
'category_id' => \App\Models\WorkerCategory::where('name', 'General Helper')->value('id') ?? (\App\Models\WorkerCategory::firstOrCreate(['name' => 'General Helper'])->id), 'experience' => $request->experience ?? 'Not Specified',
'verified' => false, 'religion' => 'Not Specified',
'status' => 'active', 'bio' => 'Hardworking and reliable General Helper available for immediate hire.',
'api_token' => $apiToken, 'category_id' => \App\Models\WorkerCategory::where('name', 'General Helper')->value('id') ?? (\App\Models\WorkerCategory::firstOrCreate(['name' => 'General Helper'])->id),
'in_country' => $inCountry, 'verified' => false,
'visa_status' => $inCountry ? $request->visa_status : null, 'status' => 'active',
'api_token' => $apiToken,
'in_country' => $inCountry,
'visa_status' => $inCountry ? $request->visa_status : null,
'preferred_job_type' => $request->preferred_job_type, 'preferred_job_type' => $request->preferred_job_type,
'live_in_out' => $request->live_in_out, 'country' => $request->country,
'country' => $request->country, 'city' => $request->city,
'city' => $request->city, 'area' => $request->area,
'area' => $request->area,
]); ]);
if (!empty($skillsArray)) { if (!empty($skillsArray)) {

View File

@ -49,25 +49,27 @@ public function updateProfile(Request $request)
$worker = $request->attributes->get('worker'); $worker = $request->attributes->get('worker');
$validator = Validator::make($request->all(), [ $validator = Validator::make($request->all(), [
'name' => 'nullable|string|max:255', 'name' => 'nullable|string|max:255',
'age' => 'nullable|integer|min:18|max:70', 'age' => 'nullable|integer|min:18|max:70',
'nationality' => 'nullable|string|max:100', 'nationality' => 'nullable|string|max:100',
'language' => 'nullable|string', 'language' => 'nullable|string',
'salary' => 'nullable|numeric|min:0', 'salary' => 'nullable|numeric|min:0',
'availability' => 'nullable|string|max:100', 'availability' => 'nullable|string|max:100',
'experience' => 'nullable|string|max:100', 'experience' => 'nullable|string|max:100',
'religion' => 'nullable|string|max:100', 'religion' => 'nullable|string|max:100',
'bio' => 'nullable|string|max:1000', 'bio' => 'nullable|string|max:1000',
'category_id' => 'nullable|exists:worker_categories,id', 'category_id' => 'nullable|exists:worker_categories,id',
'skills' => 'nullable|array', 'skills' => 'nullable|array',
'skills.*' => 'exists:skills,id', 'skills.*' => 'exists:skills,id',
'in_country' => 'nullable', 'in_country' => 'nullable',
'visa_status' => 'nullable|string|max:100', 'visa_status' => 'nullable|string|max:100',
'preferred_job_type' => 'nullable|string|max:100', 'preferred_job_type' => 'nullable|string|max:100',
'live_in_out' => 'nullable|string|max:100', 'gender' => 'nullable|string|in:male,female,other',
'country' => 'nullable|string|max:100', 'live_in_out' => 'nullable|string|in:live_in,live_out',
'city' => 'nullable|string|max:100', 'preferred_location' => 'nullable|string|max:255',
'area' => 'nullable|string|max:100', 'country' => 'nullable|string|max:100',
'city' => 'nullable|string|max:100',
'area' => 'nullable|string|max:100',
]); ]);
if ($validator->fails()) { if ($validator->fails()) {
@ -94,7 +96,9 @@ public function updateProfile(Request $request)
'category_id', 'category_id',
'visa_status', 'visa_status',
'preferred_job_type', 'preferred_job_type',
'gender',
'live_in_out', 'live_in_out',
'preferred_location',
'country', 'country',
'city', 'city',
'area' 'area'

View File

@ -20,6 +20,7 @@ class Worker extends Model
'country', 'country',
'city', 'city',
'area', 'area',
'preferred_location',
'live_in_out', 'live_in_out',
'age', 'age',
'gender', 'gender',

View File

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('workers', function (Blueprint $table) {
if (!Schema::hasColumn('workers', 'preferred_location')) {
$table->string('preferred_location')->nullable()->after('area');
}
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('workers', function (Blueprint $table) {
$table->dropColumn('preferred_location');
});
}
};

View File

@ -416,36 +416,40 @@ public function test_register_with_new_api_fields()
$fakePassport = UploadedFile::fake()->create('passport.pdf', 500, 'application/pdf'); $fakePassport = UploadedFile::fake()->create('passport.pdf', 500, 'application/pdf');
$response = $this->postJson('/api/workers/register', [ $response = $this->postJson('/api/workers/register', [
'name' => 'John New Worker', 'name' => 'John New Worker',
'phone' => '+971501111112', 'phone' => '+971501111112',
'salary' => 2200.50, 'salary' => 2200.50,
'password' => 'secret123', 'password' => 'secret123',
'passport_file' => $fakePassport, 'passport_file' => $fakePassport,
'language' => 'HI, SW', 'language' => 'HI',
'nationality' => 'Kenya', 'nationality' => 'Kenya',
'age' => 30, 'age' => 30,
'experience' => '5 Years', 'experience' => '5 Years',
'in_country' => 'true', 'in_country' => 'true',
'visa_status' => 'Tourist Visa', 'visa_status' => 'Tourist Visa',
'preferred_job_type' => 'full-time', 'preferred_job_type' => 'full-time',
'live_in_out' => 'Live-out (External housing)', 'gender' => 'male',
'country' => 'UAE', 'live_in_out' => 'live_out',
'city' => 'Dubai', 'preferred_location' => 'Dubai Marina',
'area' => 'Marina', 'country' => 'UAE',
'city' => 'Dubai',
'area' => 'Marina',
]); ]);
$response->assertStatus(201); $response->assertStatus(201);
$this->assertDatabaseHas('workers', [ $this->assertDatabaseHas('workers', [
'name' => 'John New Worker', 'name' => 'John New Worker',
'phone' => '+971501111112', 'phone' => '+971501111112',
'in_country' => true, 'in_country' => true,
'visa_status' => 'Tourist Visa', 'visa_status' => 'Tourist Visa',
'preferred_job_type' => 'full-time', 'preferred_job_type' => 'full-time',
'live_in_out' => 'Live-out (External housing)', 'gender' => 'male',
'country' => 'UAE', 'live_in_out' => 'live_out',
'city' => 'Dubai', 'preferred_location' => 'Dubai Marina',
'area' => 'Marina', 'country' => 'UAE',
'city' => 'Dubai',
'area' => 'Marina',
]); ]);
} }
@ -455,47 +459,51 @@ public function test_register_with_new_api_fields()
public function test_update_profile_with_new_api_fields() public function test_update_profile_with_new_api_fields()
{ {
$worker = Worker::create([ $worker = Worker::create([
'name' => 'Original Worker', 'name' => 'Original Worker',
'email' => 'orig@example.com', 'email' => 'orig@example.com',
'phone' => '+971502222223', 'phone' => '+971502222223',
'language' => 'SW', 'language' => 'SW',
'password' => bcrypt('password'), 'password' => bcrypt('password'),
'nationality' => 'Kenya', 'nationality' => 'Kenya',
'age' => 22, 'age' => 22,
'salary' => 1200, 'salary' => 1200,
'availability' => 'Immediate', 'availability' => 'Immediate',
'experience' => 'None', 'experience' => 'None',
'religion' => 'Christian', 'religion' => 'Christian',
'bio' => 'New helper', 'bio' => 'New helper',
'category_id' => $this->category->id, 'category_id' => $this->category->id,
'verified' => false, 'verified' => false,
'status' => 'active', 'status' => 'active',
'api_token' => 'bearer-update-token', 'api_token' => 'bearer-update-token',
]); ]);
$response = $this->withHeaders([ $response = $this->withHeaders([
'Authorization' => 'Bearer bearer-update-token', 'Authorization' => 'Bearer bearer-update-token',
])->postJson('/api/workers/profile/update', [ ])->postJson('/api/workers/profile/update', [
'in_country' => false, 'in_country' => false,
'visa_status' => null, 'visa_status' => null,
'preferred_job_type' => 'part-time', 'preferred_job_type' => 'part-time',
'live_in_out' => 'Live-in (Stay with family)', 'gender' => 'female',
'country' => 'UAE', 'live_in_out' => 'live_in',
'city' => 'Abu Dhabi', 'preferred_location' => 'Abu Dhabi',
'area' => 'Khalifa City', 'country' => 'UAE',
'city' => 'Abu Dhabi',
'area' => 'Khalifa City',
]); ]);
$response->assertStatus(200); $response->assertStatus(200);
$this->assertDatabaseHas('workers', [ $this->assertDatabaseHas('workers', [
'id' => $worker->id, 'id' => $worker->id,
'in_country' => false, 'in_country' => false,
'visa_status' => null, 'visa_status' => null,
'preferred_job_type' => 'part-time', 'preferred_job_type' => 'part-time',
'live_in_out' => 'Live-in (Stay with family)', 'gender' => 'female',
'country' => 'UAE', 'live_in_out' => 'live_in',
'city' => 'Abu Dhabi', 'preferred_location' => 'Abu Dhabi',
'area' => 'Khalifa City', 'country' => 'UAE',
'city' => 'Abu Dhabi',
'area' => 'Khalifa City',
]); ]);
} }

View File

@ -23,7 +23,7 @@ export default defineConfig({
port: 5173, port: 5173,
cors: true, cors: true,
hmr: { hmr: {
host: '192.168.0.194', host: '192.168.29.131',
}, },
watch: { watch: {
ignored: ['**/storage/framework/views/**'], ignored: ['**/storage/framework/views/**'],