notification one day before the selected date in laravel 5 - php

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 .

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.

you can use Carbon which gives you a lot of functionality working with date and Time
$currentTime = Carbon::now();
$clientsToNotif = Phonebook::with('client')->whereDate('rememberdate' , $currentTime->addDays(1))->get();
you can do any kind of notification to users now

Related

How to Set an Expiration Date after a Year in Laravel

I'm trying to make an investment website where I want to set an expiration date exactly after a year that the registration was made. Upon the registration, an initial deposit is required which is the one with the value "500" which is fixed on every registration. I want to use the created_at timestamp from my database table money_trade_deposits as the reference for the start date and calculate the expiration date based on that after a year and pass it on my laravel blade view. I'm new to laravel and I have no idea how to this.
This is my money_trade_deposits table and I wanna base the expiration date from the created_at date.
Or it it possible to add a new timestamp row which will automatically calculate the expiration date adter a year? Any help will be much appreciated. Thanks a lot!
Since the created_at is automatically casted as a Carbon instance in Laravel, you can calculate the expiration date one year after with the ->addYear() method.
Ex: $model->created_at->addYear()->toDateTimeString().
Reference: Carbon doc
You must use Carbon here to add a year from the day of the initial deposit.
Laravel automatically wraps up created_at to Carbon instance, and Carbon instance you can easily add year using addYear() function. See Documentation https://carbon.nesbot.com/docs.
I will suggest you to create a new column for expiration date and set it initially rather than adding a year to created_at each time to check expiration. Anyway, Carbon is very useful for this type of date processings.

mySQL time sum php now() in laravel seed

I have an expires_at column in mysql table. I want to fill this table using Laravel Seeding. Also i have "life_time" column in another table.
For example;
if the "life_time" is 00:05:00, my expires_at should be NOW() + 00:05:00...
expires_at is timestamp but life_time is only time. How can i create an expires_at using Carbon::now() + life_time or any time method which is showing current date.
Actually, i am trying to "A user send an image to other user using my cloud. This image has an expire date which is, if the other user does not download image from my cloud in life_time, i will delete." ... So i created a life time each file types. 5 min for images, 10 min for videos etc. I know send date and life time so i need to create expire date.
The simplest solution is to keep life_time in minutes like most of systems do and use Carbon to create expires_at:
Carbon::now()->addMinutes($lifeTime)
There are many in-built functions in Carbon. you need to use addHours(),addMinutes() , addSeconds() to add specific time in exist time.
For more information please visit : http://carbon.nesbot.com/docs/
Hope this will help you.

MySQL - Single DATETIME or Separate DATE and TIME Columns?

In my application I'm developing a functionality for creating "reminders".
A reminder has a date and a time. In my application, I have a form to create / edit reminders - this has two separate fields to input this information:
<input type="text" name="date"></input> <!-- datepicker plugin -->
<input type="text" name="time"></input> <!-- timepicker plugin -->
Now as a rule I have always used a DATETIME column whenever I have needed to store date/time, however this is the first time I'm having to store a user inputted date/time.
I figured it would be best to have seperate DATE and TIME columns, because it would be easier to insert / retrieve the data to / from my application. For example I won't have to combine the values from the two input fields to create a single value to insert in to the database. And likewise I won't have to split a single value in to two values to populate the form fields in edit mode.
But on the other hand won't it be easier to query the table if I used one column? What do you think?
You should build bottom-up (database at the bottom). Don't think about the application, just the database. Now, what makes sense at the database level. DateTime.
So you need to write extra code at the application level.
Please see it
Adding a Timepicker to jQuery UI Datepicker
http://trentrichardson.com/examples/timepicker/
convert your date time according to your mysql format and store it
$mydate = strtotime($_POST['date']);
$myfinaldate = date("d-m-y", $mydate);
$mytime = strtotime($_POST['time']);
$myfinaltime = date("H:i:s", $mytime);
Seperating columns is unlogical. You can use timestamp as datatype and you can use mktime function to parse date and time easily.
Doesn't it depends on the system you're creating.
If you want to store dates beyond 2038 I would store the datetime and time separate.
what if you are developing a reservation application and at one end you need to know on what date and at what time to schedule an appointment for a user, and at the other end, you need to match the user to a doctors schedule. You save the doctors schedule in a database and you need to know (amoung other things) when the doctor is available (on what days), and at what times. Let us forget about the on what days for a moment, and focus on the time shedule first...
You need to develop a programmable schedule so that if you know that the doctor works 6 months in a particular calendar year. (Jan - Jun), He or she may work (9-5 M,W,Fr), and (10-3 T,Th). Sat and Sunday the doctor is off. So you develop a table to hold the Daily time schedule with 2 columns to hold the daily starttime and daily end time for each day of the week. 14 columns in total and a primary and possibly secondary key. So now its time for some date arithmetic (This is where it gets hairy:-|...
You can say i your query: (mySQL)
Select such and such...
where form.theapptdatetime between doctorschedule_startime_tuesday and doctorschedule_endime_tuesday
and this will do a match to see if your datetime is within the date range of your doctorschedulestartime and endtime... but what if all you need is the time??
will the date arithmetic still work if the time value is stored as a datetime???
In other words if I have 01:00:00 as my doctorschedule_startime, is this a legitimate date value for my arithmetic to work, or will a date portion be forced upon me.
Perhaps I should store the time as a varchar, and convert it to a suitable datetime value and perform the arithmetic in the code instead of the query????
An example comes to my mind as to when have date and time split:
You could want to have DATE a part of the unique index, so that a user is only allowed to add 1 record to some table per date, but still you want to know the TIME he added it, so you keep DATE and TIME separate.

I want to hide the details of record (of database) from user when date will be expired using php

I'm totally new to php & mysql,
When I'm creating one trial application using php ,there is problem specify below,
I want to hide the details of record (of database) from user when date will be expired using php ,
When one user logedin & create one record entry that time automatically current date is also entered in database, but I want to give 1 week expiry date, after that the record will be not shown to the front end but it available in database. When the creator of this record renew this recod that time automatically date should be updated at current date, & same record will be shown as new entry
PLz help me,
I'm waiting for ur answer,
Thanks in advance.
What kind of column is the date one? Timestamp? or timedate?
Either way, you can do it like so (depending on your column type)
For timedate:
WHERE (date + INTERVAL 1 WEEK) < CURDATE()
For timestamp:
WHERE (timestamp + 604800) < UNIX_TIMESTAMP()
Let me know what you are using for your date column and I can update. You can also see the MySQL date functions here.

Recreate/find a Joomla/Community Builder 'Latest Users' module. Dates in MySQL/Joomla

When Joomla first sprung up and I moved over from Mambo I remember finding a component called Community Builder (CB) that extends the user-based interface behind Joomla.
I remember a small module I found in CB that displayed a couple of useful details about users that I want to be able to extract from my current project. These details included:
Total users registered
Total users registered per day
Total users registered per week
Total users registered per month
Latest user registered
Total visitors to the site
My question is how to recreate something very similar. I've been trying to construct an SQL statement that can manipulate the user table results and compare them to a set criteria eg. find all user's with a 'registerDate' variable within the last week.
The problem that has me lost is how to manipulate and compare a date string that resembles '2008-08-05 07:41:40'
The problem that has me lost is how to manipulate and compare a date string that resembles '2008-08-05 07:41:40'
You can have MySQL turn this into a UNIX timestamp, or you can run it through strtotime.
MySQL:
SELECT UNIX_TIMESTAMP(datetime_field) FROM table
strtotime:
$timestamp = strtotime('2008-08-05 07:41:40');

Categories