Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

moh120's avatar

The site appears without formatting

When you upload a Laravel project to the hosting, the site appears without any formatting, as shown in the image below https://drive.google.com/file/d/1ibR-4MffRWTuxv2qd-vA-ydSD3dWXVpf/view?usp=sharing

0 likes
9 replies
chiefguru's avatar

Hi @moh120 very common if you are hosting on AWS behind a load balancer and using https. Usually not loading CSS/JS because it is being served as http.

Add

        if (config('app.env') === 'production') {
            URL::forceScheme('https');
        }

to the boot method of your AppServiceProvider.

moh120's avatar

@chiefguru i use namecheap hosting Class "App\Providers\URL" not found

<?php

namespace App\Providers;

use App\Http\Traits\GetMenuTrait;
use App\Models\Cms;
use App\Models\Cookies;
use App\Models\WebsiteSetting;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use Modules\Currency\Entities\Currency;
use Modules\Language\Entities\Language;
use Modules\Location\Entities\Country;
use Modules\SetupGuide\Entities\SetupGuide;
// use App\Providers\URL;
class AppServiceProvider extends ServiceProvider
{
    use GetMenuTrait;

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // if($this->app->environment('production')) {
        //     \URL::forceScheme('https');
        // }
        if (config('app.env') === 'production') {
            URL::forceScheme('https');
        }

        Paginator::useBootstrap();

        if (! app()->runningInConsole()) {
            $setting = loadSetting();

            $default_language = Language::where('code', config('templatecookie.default_language'))->first();
            view()->share('defaultLanguage', $default_language);

            $cookies = Cookies::first();
            view()->share('cookies', $cookies);

            view()->share('website_setting', WebsiteSetting::first());
            view()->share('cms_setting', Cms::first());

            // menu data
            view()->composer('*', function ($view) {
                $view->with('public_menu_lists', $this->publicMenu());
            });
            view()->composer('*', function ($view) {
                $view->with('company_menu_lists', $this->companyMenu());
            });
            view()->composer('*', function ($view) {
                $view->with('candidate_menu_lists', $this->candidateMenu());
            });

            view()->share('hcountries', Country::all());

            $appSetup = SetupGuide::orderBy('status', 'asc')->get();
            view()->share('appSetup', $appSetup);

            view()->share('setting', $setting);
            // view()->share('currency_symbol', config('jobpilot.currency_symbol'));
            view()->share('currency_symbol', config('templatecookie.currency_symbol'));

            $languages = loadLanguage();
            $headerCountries = Country::select('id', 'name', 'slug', 'icon')->active()->get();
            $headerCurrencies = Currency::all();

            view()->share('languages', $languages);
            view()->share('headerCountries', $headerCountries);
            view()->share('headerCurrencies', $headerCurrencies);
            if ($setting) {
                if ($setting->commingsoon_mode) {
                    session()->put('commingsoon_mode', $setting->commingsoon_mode);
                }
            }
        }

        Builder::macro('whereLike', function ($attributes, string $searchTerm) {
            $this->where(function (Builder $query) use ($attributes, $searchTerm) {
                foreach (Arr::wrap($attributes) as $attribute) {
                    $query->when(
                        str_contains($attribute, '.'),
                        function (Builder $query) use ($attribute, $searchTerm) {
                            [$relationName, $relationAttribute] = explode('.', $attribute);

                            $query->orWhereHas($relationName, function (Builder $query) use ($relationAttribute, $searchTerm) {
                                $query->where($relationAttribute, 'LIKE', "%{$searchTerm}%");
                            });
                        },
                        function (Builder $query) use ($attribute, $searchTerm) {
                            $query->orWhere($attribute, 'LIKE', "%{$searchTerm}%");
                        }
                    );
                }
            });

            return $this;
        });
    }
}

Snapey's avatar

open browser developer tools, network tab.

reload the page and see what is broken (in red)

1 like
Jsanwo64's avatar

Try what @chiefguru suggested or edit your layout and change HTTP to HTTPS

                <link rel="icon" type="image/png" href="http://app.optimalhirehub.site/uploads/app/logo0oaDffQtTVZLIekAzdIrAEidj8uJ1wLrSWOjR0.png">

<link rel="preload" as="style" href="http://app.optimalhirehub.site/build/assets/app.9d4f820f.css" /><link rel="preload" as="style" href="http://app.optimalhirehub.site/build/assets/app.c8bc767d.css" /><link rel="stylesheet" href="http://app.optimalhirehub.site/build/assets/app.9d4f820f.css" /><link rel="stylesheet" href="http://app.optimalhirehub.site/build/assets/app.c8bc767d.css" /><!--only for our live site -->
<link rel="stylesheet" href="http://app.optimalhirehub.site/frontend/assets/css/free-guide.css">

<link rel="stylesheet" href="http://app.optimalhirehub.site/backend/plugins/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="http://app.optimalhirehub.site/frontend/plugins/leaflet/autocomplete.min.css">
chiefguru's avatar

Apologies @moh120 I'm so used to PHP Storm doing the hard work for me :-) You'll need to add

use Illuminate\Support\Facades\URL;
``
to the top of your AppServiceProvider

Please or to participate in this conversation.