PHP code example of rockero-cz / laravel-db-updates
1. Go to this page and download the library: Download rockero-cz/laravel-db-updates 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/ */
rockero-cz / laravel-db-updates example snippets
return new class
{
/**
* Run the updates.
*/
public function __invoke(): void
{
//
}
};
/**
* Run the updates.
*/
public function __invoke(): void
{
Post::all()->each(function (Post $post) {
$post->images()->create([
'url' => $post->image,
'title' => $post->title
]);
});
}
/**
* Run the updates.
*/
public function __invoke(): void
{
Post::query()
->where('created_at', '<', '2023-01-01')
->delete();
User::query()
->where('created_at', '<', '2023-01-01')
->delete();
}
/**
* Run the updates.
*/
public function __invoke(): void
{
Order::query()
->where('state', 'new')
->update(['state' => OrderState::CREATED]);
}