我有一个简单的想法,我只想知道实现它的最佳方法是什么?
我想让我的网站的一部分在用户登录后欢迎用户,并根据时间向用户显示欢迎信息。
例如。
早上好,xxx。
下午好,xxx。
像那样。
PS:xxxx
将是用户名。
知道我该怎么做吗?
这应该可以解决问题
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'));
}
在你的刀片中你可以做到
{{ $greetings }} {{ Auth::user()->name }}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句