PHP code example of dixieio / eloquent-model-future
1. Go to this page and download the library: Download dixieio/eloquent-model-future library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dixieio / eloquent-model-future example snippets
$scheduler->command('future:schedule')->daily();
class User extends Model
{
use Dixie\EloquentModelFuture\HasFuture;
}
$user = User::find(1);
$nextMonth = Carbon\Carbon::now()->addMonth();
// Plan a profile change for new years eve
$user->future()->plan([
'bio' => 'Happy developer time. Wooh!',
'mood' => 'excited',
])->for($nextMonth);
// Does our user have any scheduled plans for next month?
$user->future()->anyPlansFor($nextMonth); // true
// How does our user look in the future
$user->future()->see($newYearsEve);
User {
'attributes': {
'id': 1,
'name': 'John Doe',
'bio': 'Happy developer time. Wooh!',
'mood': 'excited',
[...]
}
}
// You can commit to the changes by future plans after you've seen them
// ... this will fill the `committed` column with todays date
$user->future()->see($newYearsEve)->commit(); // true
// Access all future plans for the given day
$futurePlans = $user->future()->getPlansFor(Carbon $date)
FutureCollection {
Future {
'attributes' => [
'bio' => 'Happy [...]',
'mood' => 'excited',
]
}
}
// There are some helper methods that come with the FutureCollection
$futurePlans->original(); // Original user state. Returns a user instance.
$futurePlans->result(); // How the user will look when collection is applied to user.
$futurePlans->resultDiff() // Shows which attributes has changed
// and what the values would be before and after
bash
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.