Switch case causes error

Hello, i just started learning coding
why do i get RootTagMissingFromViewException error when i use Switch case

public function render()
    {
        $current_timestamp = Carbon::now()->timestamp; // Unix timestamp 1495062127
        $date              = Carbon::parse($current_timestamp)->format('l, d F Y');

        $current_time = Carbon::parse($current_timestamp);
        $greet = floor( $current_time->hour / 6 );

        switch ($greet) {
            case 0:
                return "Good night!";
                break;
            case 1:
                return "Good morning!";
                break;
            case 2:
                return "Good afternoon!";
                break;
            case 3:
                return "Good evening!";
                break;
        };

        return view('livewire.greater', [
            'date' => $date,
            'greet' => $greet,
        ]);
    }

if i remove the switch case then the page renders fine
i dont get it ?

I think you forgot the default case.
please check swith case syntax.

Can you post you component.blade.php code? I have a feeling you have some livewire-y things in the root element of your blade code. You should always have an untouched root element.

Hopefully it looks something like this:

<div> <!-- it's important to leave this element clear of livewire stuffs -->
    <div>{{ $greet }}</div>
    <div>Today is {{ $date }}</div>
</div>

Yea its like this

<div>
    <div class="row justify-content-center mb-5 text-light">
        <div class="col-auto text-center">
            <span class="title-decorative" id="header_date">{{ $date }}</span>
            <h1 class="display-4" id="header_greet">{{ $greet }}</h1>
            </div>
    </div>
</div>

but i fixed it like this

<?php

namespace App\Http\Livewire;

use Carbon\Carbon;
use Livewire\Component;

class Greater extends Component
{
    private function date()
    {
        $current_timestamp = Carbon::now()->timestamp; // Unix timestamp 1495062127
        $date              = Carbon::parse($current_timestamp)->format('l, d F Y');

        return $date;
    }

    private function greet()
    {
        $current_timestamp = Carbon::now()->timestamp; // Unix timestamp 1495062127

        $current_time = Carbon::parse($current_timestamp);
        $greet        = floor($current_time->hour / 6);

        switch ($greet) {
            case 0:
                return "Good night!";
                break;
            case 1:
                return "Good morning!";
                break;
            case 2:
                return "Good afternoon!";
                break;
            case 3:
                return "Good evening!";
                break;
        };
    }

    public function render()
    {
        $date  = $this->date();
        $greet = $this->greet();

        return view('livewire.greater', [
            'date'  => $date,
            'greet' => $greet,
        ]);
    }
}