duan2477 2018-06-06 20:12
浏览 510
已采纳

在laravel 5中选定日期前一天发出通知

i am working on laravel dates and i want laravel to give notification a day before or the same selected day in database how can i do that here is a part of my code : here is my controller i save remember_date in phonebook model

public function index()
{

    $current_time = Verta::now();
    $phonebooks = Phonebook::with('client')->get();
    return view('admin.phonebooks.index', compact('phonebooks'))->with('current_time',$current_time);
}

and here is the migration of my phonebooks table

 public function up()
{
    Schema::create('phonebooks', function (Blueprint $table) {
        $table->increments('id');
        $table->text('title');
        $table->longText('description');
        $table->integer('client_id');
        $table->dateTime('calldate');
        $table->dateTime('rememberdate');
        $table->timestamps();
    });
}

now i want to give notification to call the client 1 day before or the day which is stored in rememberdate .

  • 写回答

2条回答 默认 最新

  • doubi2145 2018-06-06 20:24
    关注

    In case: If you just want static notification section on you page
    If you just wanna show something on the page as notification then just fetch data based on your condition that matches with the notification rule.

    Steps:

    • Get current date (php current date)
    • Calculated date: Add a day to the current date (current date+1 day)
    • fetch record by matching the Calculated date with the rememberdate in DB
    • display your notification if any record found in DB, if record not found then "No notification found"

    For date operations you can use core php and add one day to current date. But I would recommend you to use Carbon lib in laravel.

    Examples using Carbon to add days in current date time Link

    Update based on your comment:
    I am sorry, actually I dont understand that calendar (jalali calendar) but simply adding one day will work for any calendar. First explore Carbon if that support your calendar. But I had similar problem in past. Nepal got its own dates and calendar system and I had to develop an application. What I did is I did all the operations/calculations and storing data in DB in standard time (English date-time) that servers and mysql default and then on application only at the time of displaying data, I display date-time in local format (Nepal's Local Calendar).

    At the time of displaying data on web page (UI), I used date converter class that I had written to convert date-time from Nepal date-time to English date-time and vise versa.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试