我有一個簡單的想法,我只想知道實現它的最佳方法是什麼?laravel中的計時消息5
我想讓我的網站的一部分,以在用戶登錄後歡迎用戶,並根據時間顯示歡迎注意到用戶。
例如。
早上好,xxx。
下午好,xxxx。
那樣。
PS:xxxx
將成爲用戶名。
任何想法我可以做到這一點?
我有一個簡單的想法,我只想知道實現它的最佳方法是什麼?laravel中的計時消息5
我想讓我的網站的一部分,以在用戶登錄後歡迎用戶,並根據時間顯示歡迎注意到用戶。
例如。
早上好,xxx。
下午好,xxxx。
那樣。
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 }}
完美的作品,但我不知道爲什麼它顯示出問候箱! HTTP:// imgur。com/a/TjFQT – djhru
您需要檢查您想要顯示內容的位置並進行相應渲染 – linktoahref
我已將{{$問候語}}放置在您看到的名稱相同的位置,但它顯示在'
'標籤在頂部!名字是在正確的地方,但問候上升! – djhru鑑於
@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');
創建一個輔助函數來包裝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');
}
的([取決於一天的時間運行代碼]可能的複製https://stackoverflow.com/questions/8652502/run-code-depending-on當天的時間) – linktoahref
@linktoahref確定它的工作原理,但我如何得到涉及{{Auth :: user() - > name}}? – djhru
在我的例子中,我說過早安xxxx這些'xxxx'應該是用戶名。 – djhru