<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Models\About;
use App\Models\CompanySchedule;
use App\Models\Email;
use App\Models\Feature;
use App\Models\ManufacturingCompany;
use App\Models\Partner;
use App\Models\Post;
use App\Models\Project;
use App\Models\Service;
use App\Models\Skill;
use App\Models\Slider;
use App\Models\User;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        // $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {

        $sliders = Slider::orderBy('id', 'asc')->get();
        $company_schedules = CompanySchedule::orderBy('id', 'asc')->get();
        $users = User::whereRelation('roles', 'name', 'user')->get();
        $services = Service::where('parent_id' , null)->get();
        $posts = Post::all();
        $partners = Partner::get()->chunk(10);
        $clients = ManufacturingCompany::all();

        return view('web.home', compact('sliders' , 'partners', 'company_schedules', 'posts' , 'services', 'users', 'clients'));
    }

    // lang
    public function lang($lang)
    {
        // change language
        session()->put('lang', $lang);

        // return
        return redirect()->back();
    }

    // subscribe
    public function subscribe(Request $request)
    {

        Email::create($request->all());

        return redirect()->back()->with('success', 'Subscribe Successfully');
    }
}
