<?php


namespace App\Http\Controllers\front;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\workRequest;
use App\Models\job;
use Illuminate\Support\Str;
use LaravelLocalization;
use App\Models\logo;
use App\Models\invest_inner;
use App\Models\invest;
use App\Models\phone;
use App\Models\email;
use App\Models\Address;
use App\Models\service;
use App\Traits\allTraits;


class jobController extends Controller
{
    use allTraits;

    public function jobs() {

        $logos =  logo::All();
        $invests =  invest::select('id',
        'slug',
        'title_' . LaravelLocalization::getCurrentLocale() . ' as title') -> get();

        $phones =  phone::All();
        $emails =  email::All();
        $addresses =  address::select('id',
        'title_' . LaravelLocalization::getCurrentLocale() . ' as title', ) -> get();



        $services =  service::select('id',
        'slug',
        'photo',
        'title_' . LaravelLocalization::getCurrentLocale() . ' as title',) -> get();
         $allServices = $services;

        return view('front.jobForm', compact('logos', 'allServices',  'services', 'invests', 'phones', 'emails', 'addresses'));
    }


    public function workPost(workRequest $request)
    {




        $file_nameCV = $this->saveImageCv($request->cv, 'images/cv');
        $file_nameNationalID = $this->saveImageNationalID($request->NationalID, 'images/NationalID');

        work::create([
            'cv' => $file_nameCV,
            'NationalID' => $file_nameNationalID,
            'Name' => $request -> Name,
            'email' => $request -> email,
            'phone' => $request -> phone,
            'governorate' => $request -> governorate,
            'birthOfDate' => $request -> birthOfDate,
            'address' => $request -> address,
            'qualification' => $request -> qualification,
            'massage' => $request -> massage,
        ]);

        return redirect()->back()->with(['successAdd' => '']);

    }


}
