我有一个简单的想法,我只是想知道实现它的最佳方法是什么?
我希望我的网站成为用户登录后欢迎用户的一部分,并根据时间向用户显示欢迎提示。
例如
早上好,xxx。
下午好,xxxx。
像那样。 PS:xxxx
将是用户的用户名。
知道我该怎么做吗?
答案 0 :(得分:3)
这应解决问题
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 }}
答案 1 :(得分:0)
创建一个帮助函数来包装http://carbon.nesbot.com/docs/#api-comparison 像:
<?php
function say_hello(\Carbon\Carbon $carbon) {
if($carbon->hour > 12) {
return lang('good_morning');
} elseif ($carbon->hour > 19) {
return lang('good_evening');
}
return lang('good_afternoon');
}
答案 2 :(得分:-1)
在视图中
@if(session('status'))
<div class="alert alert-success">
{{ session('status') }}
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
</div>
@endif
在控制器
中return View::make('home')->with('status','msg');