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

emresudo's avatar

Laravel [9] html sometimes does not render properly

Actually this problem i noticed a have few weeks ago.

I using Docker for Windows and laravel running on docker.

I tried using local and remote database, but nothing has changed.

What is the problem? I cant detect anything.

This page is look like good rendered. But if i change page or reload, any place is look like this in page. I tried some things but didnt work.

If you want to see normal and wrong page code, please check.

https://www.diffchecker.com/LMsiJcjB

https://www.diffchecker.com/BQ0mfCwo

https://www.diffchecker.com/gi8eOsIO Please check image:

This is a normal page

https://i.stack.imgur.com/RnKhN.png

Not every time, just sometimes :/

https://i.stack.imgur.com/QOVUl.png

https://i.stack.imgur.com/v7lPW.png

list.blade.php

@extends('admin.layouts.master')

@section('title', 'Tüm Siparişler')
@section('content')

    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="row mb-2">
                        <div class="col-sm-4">
                            <div class="search-box me-2 mb-2 d-inline-block">
                                <div class="position-relative">
                                    <form method="GET" action="{{ route('admin_order_status', $status) }}">
                                        <input type="text" name="search" class="form-control"
                                            value="{{ $search }}" placeholder="Arama...">
                                        <i class="bx bx-search-alt search-icon"></i>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="table-responsive">
                        <table class="table align-middle table-nowrap table-check">
                            <thead class="table-light">
                                <tr>
                                    <th style="width: 20px;" class="align-middle">
                                        <div class="form-check font-size-16">
                                            <input class="form-check-input" type="checkbox" id="checkAll">
                                            <label class="form-check-label" for="checkAll"></label>
                                        </div>
                                    </th>
                                    <th class="align-middle">ID</th>
                                    <th class="align-middle">Ürün</th>
                                    <th class="align-middle">Müşteri</th>
                                    <th class="align-middle">Fiyat</th>
                                    <th class="align-middle">Sonraki ödeme tarihi</th>
                                    <th class="align-middle">Durum</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($orders as $item)
                                    <tr>
                                        <td>
                                            <div class="form-check font-size-16">
                                                <input class="form-check-input" type="checkbox"
                                                    id="orderidcheck{{ $item->order_id }}">
                                                <label class="form-check-label"
                                                    for="orderidcheck{{ $item->order_id }}"></label>
                                            </div>
                                        </td>
                                        <td>
                                            <a href="{{ route('admin_order_view', $item->order_id) }}"
                                                class="text-body fw-bold">
                                                {{ $item->order_id }}
                                            </a>
                                        </td>
                                        <td>
                                            <a href="{{ route('admin_order_view', $item->order_id) }}"
                                                class="text-body fw-bold">
                                                {{-- @lang("admin/orders.type.{$item->data->product_name}") --}}
                                                {{ $item->data->product_name }}
                                            </a>
                                        </td>
                                        <td>
                                            <a href="{{ route('admin_users_summary', $item->user_id) }}">
                                                {{ $item->first_name }} {{ $item->last_name }}
                                            </a>
                                        </td>
                                        <td>
                                            {{ $item->amount }} ₺
                                        </td>
                                        <td class="fw-bold">
                                            @if ($item->next_paid_at)
                                                {{ Carbon\Carbon::parse($item->next_paid_at) }}
                                            @else
                                                -
                                            @endif
                                        </td>
                                        <td>
                                            <span
                                                class='badge badge-pill bg-{{ config("enums.order_status_color.$item->status") }} font-size-12'>
                                                @lang("admin/orders.$item->status")
                                            </span>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    {!! $orders->withQueryString()->links() !!}
                </div>
            </div>
        </div>
    </div>



@endsection

Controller.php

class OrdersController extends Controller
{

    public function indexByStatus(Request $request, string $status = 'all')
    {

        $search = $request->get('search');

        $orders = Order::query();
        $orders = $orders->join('users', 'users.id', '=', 'orders.user_id');

        $orders = $orders->select([
            'users.id as user_id',
            'users.first_name',
            'users.last_name',
            'orders.id as order_id',
            'orders.amount',
            'orders.data',
            'orders.payment_method',
            'orders.invoice_id',
            'orders.status',
            'orders.next_paid_at',
        ]);

        if ($search) {
            if ($status != 'all') {
                $orders->where('orders.status', $status);
            }
            $orders->where(function ($q) use ($search) {
                return
                    $q->orWhere('users.first_name', 'LIKE', "%$search%")
                    ->orWhere('users.last_name', 'LIKE', "%$search%")
                    ->orWhere('orders.data', 'LIKE', "%$search%");
            });
        } else {
            if ($status != 'all') {
                $orders->where('orders.status', $status);
            }
        }

        $orders = $orders->orderByDesc('orders.created_at');
        $orders = $orders->paginate(10);

        return view(
            'admin.orders.allorders',
            [
                'orders' => $orders,
                'search' => $search,
                'status' => $status,
            ]
        );
    }
}

Model.php

class Order extends Model
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'status',
        'payment_method',
        'billing_period',
        'data',
        'user_id',
        'invoice_id',
        'amount',
        'next_paid_at',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'data' => 'object',
        'next_paid_at' => 'timestamp',
        'created_at' => 'timestamp',
        'updated_at' => 'timestamp'
    ];

    public function user()
    {
        return $this->hasOne(User::class, 'id', 'user_id');
    }
}
0 likes
44 replies
MohamedTammam's avatar

Mostly you have unclosed tag, search for something like that.

emresudo's avatar

@MohamedTammam problem not this. I closed every tag, wrong page showing just sometimes. I dont detected anything.

jlrdw's avatar

Do smaller portions of the form to see when error begins.

click's avatar

Your input tag is not closed correctly.

 <input class="form-check-input" type="checkbox" id="orderidcheck{{ $item->order_id }}">

should be

 <input class="form-check-input" type="checkbox" id="orderidcheck{{ $item->order_id }}" />

if that does not solve it check it one by one, remove a column see if it is fixed until the moment you found the problem.

rodrigo.pedra's avatar

@click

The <input> tag does not accept content, so it does not need a close tag or to be self-closed. Same is true for other "empty" tags such as <img>, <hr>, <br>, and others.

See the code samples from the specification:

Although in some code samples on MDN it shows as self-closing, in most code samples from MDN the "try it" code sample code shows it unclosed:

In any case the specification overrules this matter.

On the older XHTML specification it needed to be self-closed. In HTML 5 it does not.

Note: it is unnecessary to close it, but if one does it is simply ignored.

rodrigo.pedra's avatar

@click no worries, our field changes too fast and too much, it is hard to know everything.

Have a nice day =)

rodrigo.pedra's avatar

@emresudo can you share some of your config and lang files?

More specifically your:

  • ./config/enum.php file, precisely the order_status_color key
  • your ./lang/en/admin/orders.php file (replace en by the language you are using)
rodrigo.pedra's avatar
@lang("admin/orders.$item->status")

will compile to:

<?php echo app('translator')->get("admin/orders.$item->status"); ?>

So, if you have a translation key that includes a < character, or an unclosed HTML tag, it will be outputted unescaped.

rodrigo.pedra's avatar

If you need to escape your translation keys replace:

@lang("admin/orders.$item->status")

by

{{ trans("admin/orders.$item->status") }}
emresudo's avatar

@rodrigo.pedra

I don't always encounter this problem. The problem here is actually, sometimes everything is fine, sometimes it is completely broken. Also I have this problem every page :(

./config/enum.php

<?php

return [
    'order_status' => [
        'active',
        'setup_pending',
        'payment_pending',
        'suspend',
        'cancelled',
        'terminated'
    ],
    'order_status_color' => [
        'payment_pending' => 'info',
        'setup_pending' => 'dark',
        'active' => 'success',
        'suspend' => 'warning',
        'cancelled' => 'secondary',
        'terminated' => 'danger'
    ],
    'invoice_status' => [
        'draft',
        'payment_pending',
        'unpaid',
        'refunded',
        'paid',
        'cancelled'
    ],
    'invoice_status_color' => [
        'draft' => 'secondary',
        'payment_pending' => 'warning',
        'unpaid' => 'dark',
        'refunded' => 'info',
        'paid' => 'success',
        'cancelled' => 'danger'
    ],
    'payment_methods' => [
        'bank_transfer',
        'shopier',
        'paytr',
        'user_credit'
    ],
    'account_status' => [
        'active',
        'inactive',
        'closed'
    ],
    'ticket_status' => [
        'open',
        'answered',
        'user_reply',
        'in_progress',
        'waiting_accounting',
        'closed'
    ],
    'ticket_status_color' => [
        'open' => 'success',
        'closed' => 'secondary',
        'answered' => 'primary',
        'user_reply' => 'warning',
        'in_progress' => 'danger',
        'waiting_accounting' => 'info'
    ],
    'billing_period' => [
        'recurring_monthly',
        'recurring_yearly',
        'onetime',
        'free'
    ],
    'auto_setup' => [
        'after_payment',
        'manual'
    ],
    'product_type' => [
        'hosting',
        'reseller_hosting',
        'dedicated_server',
        'other',
    ]
];

./lang/tr/admin/orders.php

<?php

return [

    'payment_pending' => 'Ödeme bekleniyor',
    'setup_pending' => 'Kurulum bekleniyor',
    'active' => 'Aktif',
    'suspend' => 'Askıda',
    'cancelled' => 'İptal edildi',
    'terminated' => 'Sonlandırıldı',

    'free' => 'Ücretsiz',
    'onetime' => 'Tek seferlik',
    'recurring_monthly' => 'Aylık yenilenen',
    'recurring_yearly' => 'Yıllık yenilenen',
];
rodrigo.pedra's avatar

@emresudo

This is very strange... the only thing I can think of is if you have any config, or other PHP file with a space before the PHP opening tag.

If you are developing in a Linux or macOS box, run this command in a terminal from your project's root directory:

grep -Pazo '^\s+<\?php' -r .

This command will search for any files that have any number of "space" characters (new-lines included) before an opening PHP tag.

As others already have said, this could be a caching problem. Delete any PHP files in your project's ./bootstrap/cache folder and run:

php artisan optimize:clear

This command, among clearing other caches, will also delete any cached view files.

You can also try deleting your project's ./vendor directory and run composer install to ensure all dependencies were not changed.

emresudo's avatar

@rodrigo.pedra

grep -Pazo '^\s+<\?php' -r . >> file not found so nothing change.

optimize:clear >> nothing change.

vendor reinstall >> nothing change.

I'm develop on WSL2 with Docker Desktop.

Tray2's avatar

@emresudo My guess is that something that you print here breaks your html

{!! $orders->withQueryString()->links() !!}

Try with

{{ $orders->withQueryString()->links() }}

If there is no difference, try removing the pagination completely to see if the problem goes away.

emresudo's avatar

@Tray2 I'm directly removed pagination code but nothing change :( I don't understand why god why :(( And I removed pagination for sql.

// $orders = $orders->paginate(10); // old
$orders = $orders->get();  //new

But nothing change.

Tray2's avatar

@emresudo Try changing this line

class='badge badge-pill bg-{{ config("enums.order_status_color.$item->status") }} font-size-12'>

To

class="badge badge-pill bg-{{ config("enums.order_status_color.$item->status") }} font-size-12">

It could the that something there contains a ' thus breaking the code.

emresudo's avatar

@Tray2 It didn't work, sometimes I need to refresh the page 50 times to see the faulty page again.

Tray2's avatar

@emresudo Check your database to see if any of the whatever it is contains any <> ' " that may break it.

They should be escaped already but the might not be.

emresudo's avatar

@Tray2 Thank you for your effort but wrong page not showing everytime.

http://localhost/ssd/invoices/all

For example;

I just refresh this page. 10 times everything is okey but 2 times not properly.

And I added 3 links for html output different. Please check links. Links has in the question.

click's avatar

@emresudo https://www.diffchecker.com/BQ0mfCwo The HTML is malformed on line 344 but in your original blade file posted in the comment I don't see any php/blade that does something on that spot... so that is strange. Do you have any service that maybe tries to minify the HTML or something and that might fail?

See line 2, 3 and 4.

 <div class="table-responsive">
                        <t <="" a="">
                                    
                                    </t><table class="table align-middle table-nowrap table-check">
                            <thead class="table-light">
                                <tr>
                                    <th style="width: 20px;" class="align-middle">
                                        <div class="form-check font-size-16">
                                            <input class="form-check-input" type="checkbox" id="checkAll">
                                            <label class="form-check-label" for="checkAll"></label>
                                        </div>
                                    </th>
                                    <th class="align-middle">ID</th>
                                    <th class="align-middle">Ürün</th>
                                    <th class="align-middle">Müşteri</th>
                                    <th class="align-middle">Tutar (Kdv dahil)</th>
                                    <th class="align-middle">Sonraki ödeme tarihi</th>
                                    <th class="align-middle">Durum</th>
                                </tr>
                            </thead>
1 like
Tray2's avatar

@emresudo Ok, something in your code or database breaks the html some of the time, but what it is, I have no clue about. There must be something that becomes different between a working and a not working page.

emresudo's avatar

@Tray2 I think problem is blade. Doesn't have any html code in my database. You have github repo access. If you want to help me, please run in your localhost and test it.

Tray2's avatar

@emresudo Will give it a go. I suggest removing the .env from the git repository though,

Tray2's avatar

@emresudo I can't reproduce the problem since I don't have the needed records in the database. However, I checked your screenshots again, and it seems that there is a difference between them. that are showing different pages in the pagination, that tell me that one or more of the names in the database contains characters that causes the page to break.

So I suggest exporting all the records from the table(s) that is used by the controller in question, and create a seeder. Then seed the database with it, that way all html characters will be rendered safe, and will not break your page.

emresudo's avatar

@Tray2 Oh my god, if you have docker for windows, please clone this repo in wsl. And run this commands.

./vendor/bin/sail up -d

./vendor/bin/sail artisan migrate:fresh --seed

emresudo's avatar

@Tray2 Other answer, my .env file is empty. I have password and ip address but it's not true for auth.

Tray2's avatar

@emresudo On a Mac running valet, so can't do that. I removed docker since I never use it.

I take it you found the issue, something with the character set on windows/wsl.

kiri1101's avatar

@emresudo try clearing your browser cache Ctrl + f5 and clearing your laravel cache php artisan cache:clear. If it persists, check for vite or webpack compiler errors/warnings in your terminal

kiri1101's avatar

@emresudo Cuz you're cache might contain precompiled CSS that conflict with any new CSS you just called or modified in your view. Running php artisan cache:clear helps clean your cache

emresudo's avatar

@kiri1101 I don't think so, Because I don't have dynamic css. Also I see this problem when page refresh. Even the data does not change.

Snapey's avatar

check the clock in your container. Laravels view compilation checks the timestamp of the edited file to see if it is newer than the cache. Since effectively, you edit the files under one OS but then process it in another any clock differences can cause intermittent issues

1 like
emresudo's avatar

@Snapey Yes, i check Windows, Wsl2(Ubuntu) and in container, i set every time and timezone but it didn't change.

iprastha's avatar

Try to check if your source code and blade files are saved in correct encoding, that is UTF-8. If you are using vs-code, check on the lower right corner, it should indicate the encoding like UTF-8, if not then there might be encoding issues, you should re-save the file with the correct encoding (UTF-8)

Please or to participate in this conversation.