Laravel 5 中的定时消息

djh*_*hru -1 php laravel

我有一个简单的想法,我只是想知道实现它的最佳方法是什么?

我想在用户登录后制作我的网站的一部分来欢迎用户,并根据时间向用户显示欢迎信息。

例如。

早上好,xxx。

下午好,xxxx。

像那样。

PS:xxxx将是用户的用户名。

知道我该怎么做吗?

lin*_*ref 7

这应该可以解决问题

public function index() {

    $greetings = "";

    /* This sets the $time variable to the current hour in the 24 hour clock format */
    $time = date("H");

    /* Set the $timezone variable to become the current timezone */
    $timezone = date("e");

    /* If the time is less than 1200 hours, show good morning */
    if ($time < "12") {
        $greetings = "Good morning";
    } else

    /* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */
    if ($time >= "12" && $time < "17") {
        $greetings = "Good afternoon";
    } else

    /* Should the time be between or equal to 1700 and 1900 hours, show good evening */
    if ($time >= "17" && $time < "19") {
        $greetings = "Good evening";
    } else

    /* Finally, show good night if the time is greater than or equal to 1900 hours */
    if ($time >= "19") {
        $greetings = "Good night";
    }

    return view('home', compact('greetings')); 
}
Run Code Online (Sandbox Code Playgroud)

在你的刀刃上你可以做到

{{ $greetings }} {{ Auth::user()->name }}
Run Code Online (Sandbox Code Playgroud)