<?php

namespace App\View\Composers;

use App\Models\Category;
use App\Models\CountryLocale;
use Illuminate\View\View;

class CategoryComposer
{
    public function compose(View $view)
    {
        $current_country_locale = request()->session()->get('view_country_locale');

        if (is_null($current_country_locale)) {
            $current_country_locale = CountryLocale::where('slug', config('platform.general.fallback_country_slug'))->first();
        }

        $categories = Category::where('country_locale_id', $current_country_locale->id)->get();

        $view->with('categories', $categories);

    }
}
