首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Blade渲染工作计划的更好方法

使用Blade渲染工作计划的更好方法
EN

Stack Overflow用户
提问于 2016-04-08 08:27:31
回答 1查看 57关注 0票数 2

下面是我现在是怎么做的:

代码语言:javascript
复制
<p><strong>@lang('date.monday')</strong>    <span>{{ $profile->getSchedule()[\Carbon\Carbon::MONDAY]['from'] }}:00 - {{ $profile->getSchedule()[\Carbon\Carbon::MONDAY]['to'] }}:00</span></p>
<p><strong>@lang('date.tuesday')</strong>   <span>{{ $profile->getSchedule()[\Carbon\Carbon::TUESDAY]['from'] }}:00 - {{ $profile->getSchedule()[\Carbon\Carbon::TUESDAY]['to'] }}:00</span></p>
<p><strong>@lang('date.wednesday')</strong> <span>{{ $profile->getSchedule()[\Carbon\Carbon::WEDNESDAY]['from'] }}:00 - {{ $profile->getSchedule()[\Carbon\Carbon::WEDNESDAY]['to'] }}:00</span></p>
<p><strong>@lang('date.thursday')</strong>  <span>{{ $profile->getSchedule()[\Carbon\Carbon::THURSDAY]['from'] }}:00 - {{ $profile->getSchedule()[\Carbon\Carbon::THURSDAY]['to'] }}:00</span></p>
<p><strong>@lang('date.friday')</strong>    <span>{{ $profile->getSchedule()[\Carbon\Carbon::FRIDAY]['from'] }}:00 - {{ $profile->getSchedule()[\Carbon\Carbon::FRIDAY]['to'] }}:00</span></p>
<p><strong>@lang('date.saturday')</strong>  <span>{{ $profile->getSchedule()[\Carbon\Carbon::SATURDAY]['from'] }}:00 - {{ $profile->getSchedule()[\Carbon\Carbon::SATURDAY]['to'] }}:00</span></p>
<p><strong>@lang('date.sunday')</strong>    <span>{{ $profile->getSchedule()[\Carbon\Carbon::SUNDAY]['from'] }}:00 - {{ $profile->getSchedule()[\Carbon\Carbon::SUNDAY]['to'] }}:00</span></p>

调度存储为JSON并强制转换为数组,即$profile->getSchedule()将此结构作为数组返回。示例:

代码语言:javascript
复制
{
  "0" : {
    "from" : "05",
    "to" : "15"
  },
  "1" : {
    "from" : "14",
    "to" : "08"
  },
  "2" : {
    "from" : "10",
    "to" : "04"
  },
  "3" : {
    "from" : "11",
    "to" : "00"
  },
  "4" : {
    "from" : "21",
    "to" : "19"
  },
  "5" : {
    "from" : "02",
    "to" : "20"
  },
  "6" : {
    "from" : "13",
    "to" : "20"
  }
}
EN

回答 1

Stack Overflow用户

发布于 2016-04-08 09:01:24

在控制器中,运行$profile->getSchedule()一次,然后进行碳解析并将$schedule发送到视图。

$schedule可能看起来像

代码语言:javascript
复制
[
  Monday:{
    open:'08:00',
    close: '22:00'
  }
  ...
];

然后,在blade中,您只需执行以下操作:

代码语言:javascript
复制
@foreach($schedule as $day => $hours)

  <p><strong>{{$day}}</strong>
  <span>{{ $hours['open'] }} - {{ $hours['close'] }}</span></p>

@endforeach
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36489497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档