Get The Difference Between Two Date In Laravel Using jpmurray/laravel-countdown
In this post we will give you information about Get The Difference Between Two Date In Laravel Using jpmurray/laravel-countdown. Hear we will give you detail about Get The Difference Between Two Date In Laravel Using jpmurray/laravel-countdownAnd how to use it also give you demo for it if it is necessary.
Today, Laravelcode share with you how to get defference between two date in laravel. some time you need two calculation of defference between two date. in many type situation like generate report, generate chart etc..
You also done this with laravel carbon, but in this tutorials we are share with you with one laravel package jpmurray/laravel-countdown. this package provide very easy way to calculate two deffrence date duration.
Step : 1 Install package
First we need to install jpmurray/laravel-countdown laravel package in our laravel application run following command.
composer require jpmurray/laravel-countdown
Step : 2 Configure package
After installtion done then configure package. so, open our config/app.php file and set service provider and aliases in it. just following this way
'providers' => [
....
jpmurrayLaravelCountdownCountdownServiceProvider::class,
],
'aliases' => [
....
'Countdown' => jpmurrayLaravelCountdownFacadesCountdownFacade::class,
],
Step : 3 Usage
Then after you can use in you laravel controller in following way
How to solve 'There are no commands defined in the "cashier" namespace' in Laravel 5
In this post we will give you information about How to solve 'There are no commands defined in the "cashier" namespace' in Laravel 5. Hear we will give you detail about How to solve 'There are no commands defined in the "cashier" namespace' in Laravel 5And how to use it also give you demo for it if it is necessary.
When i did start to learn "Laravel Cashier" and i was following step by step of laravel official document, but i run bellow command :
php artisan cashier:table users
At that time i found following error on my terminal:
[SymfonyComponentConsoleExceptionCommandNotFoundException]There are no commands defined in the "cashier" namespace.
I try to solve this error, i also clear all cache and add service provider, it means i try totally and i can't found solution for this error, but you can also add migration like this way if you want it is a same like we did bellow command. so first run command for create migration:
php artisan make:migration add_cashier_table_fields
ok, now put bellow content on following file :
Migration:
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
class AddBillTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function ($table) {
$table->string('stripe_id')->nullable();
$table->string('card_brand')->nullable();
$table->string('card_last_four')->nullable();
$table->timestamp('trial_ends_at')->nullable();
});
Schema::create('subscriptions', function ($table) {
$table->increments('id');
$table->integer('user_id');
$table->string('name');
$table->string('stripe_id');
$table->string('stripe_plan');
$table->integer('quantity');
$table->timestamp('trial_ends_at')->nullable();
$table->timestamp('ends_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
}
}
Hope this code and post will helped you for implement How to solve 'There are no commands defined in the "cashier" namespace' in Laravel 5. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
[ADDCODE]
use jpmurrayLaravelCountdownCountdown;
// To get time from 5 years ago until now, you can do the following.
// Note that you can send a string to the from and to methods, we will
// try to parse it with Carbon behind the scene
$countdown = Countdown::from(CarbonCarbon::now()->subYears(5))->to(Carbon::now())->get();
// The above will return the Countdown class where you can access the following values.
// Those mean that from 5 years ago to now, there is 5 years, 1 week, 1 day, 2 hours 15 minutes and 23 seconds
$countdown->years; // 5
$countdown->weeks; // 1
$countdown->days; // 1
$countdown->hours; // 2
$countdown->minutes; // 15
$countdown->seconds; // 23
// It will of course, also work in reverse order of time.
// This will get the time between now and some future date
$countdown = Countdown::from(CarbonCarbon::now())->to(CarbonCarbon::now()->addYears(5))->get();
Step : 3 Trait
// For convenience, we provide a trait that you can add to any model in your Laravel app that provides
// quick methods to get the values of time between dates. For example:
use jpmurrayLaravelCountdownTraitsCalculateTimeDiff;
class User extends Authenticatable
{
use Notifiable, CalculateTimeDiff;
//...
}
// This enables the following:
// You should have casted your attributes to dates beforehand
$user = User::find(1);
$user->elapsed('trial_ends_at'); // get the time elapsed between the date in attribute trial_ends_at to now
$user->until('trial_ends_at'); // get the time from now until the date in attribute trial_ends_at
If you face any problem then please write a comment or give some suggestions for improvement. Thanks…
Hope this code and post will helped you for implement Get The Difference Between Two Date In Laravel Using jpmurray/laravel-countdown. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs
