Skip to content

Commit e1ca096

Browse files
authored
Merge pull request #612 from wayofdev/feat/docs
2 parents bde7f51 + f59a07d commit e1ca096

File tree

5 files changed

+169
-18
lines changed

5 files changed

+169
-18
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,11 @@ test-cc: ## Run project php-unit and pest tests in coverage mode and build repor
190190
docs-deps-update: ## Check for outdated dependencies and automatically update them using pnpm
191191
cd docs && $(NPM_RUNNER) run deps:update
192192
.PHONY: docs-deps-update
193+
194+
docs-deps-install: ## Install dependencies for documentation using pnpm
195+
cd docs && $(NPM_RUNNER) install
196+
.PHONY: docs-deps-install
197+
198+
docs-up: ## Start documentation server
199+
cd docs && $(NPM_RUNNER) dev
200+
.PHONY: docs-up

docs/pages/contributing.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The latest changes are always in master branch, so please make your Pull Request
88

99
## 💻 Workflow
1010

11-
<Callout type="warning">
11+
<Callout type="warning" emoji="⚠️">
1212
Please feature/fix/update... into individual PRs (not one changing everything)
1313
</Callout>
1414

docs/pages/services/factories.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Callout } from "nextra-theme-docs";
22

3-
Like [Eloquent Factories](https://laravel.com/docs/10.x/eloquent-factories) this package enables you to define factories for your database models, integrating Cycle ORM with Laravel's elegant syntax and functionality.
3+
Like [Eloquent Factories](https://laravel.com/docs/10.x/eloquent-factories) this package enables you to define factories for your entities, integrating Cycle ORM with Laravel's elegant syntax and functionality.
44

55
This feature is available through the [wayofdev/laravel-cycle-orm-factories](https://github.com/wayofdev/laravel-cycle-orm-factories), be sure to check [installation](/installation#-database-factories-optional) instructions.
66

@@ -163,7 +163,7 @@ State manipulation methods allow you to define discrete modifications that can b
163163

164164
State transformation methods typically call the state method provided by `WayOfDev\DatabaseSeeder\Factories\AbstractFactory` class. The state method accepts a closure which will receive the array of raw attributes defined for the factory and should return an array of attributes to modify:
165165

166-
<Callout type="note">
166+
<Callout type="info" emoji="💡">
167167
💡 It is non-destructive, it will only update the properties passed in the returned array and will not remove any properties from the definition array.
168168
</Callout>
169169

@@ -436,7 +436,7 @@ class PostFactory extends AbstractFactory
436436
}
437437

438438
// example with User created by factory
439-
public function withUser(UserFactory $userFactory): self
439+
public function withUser(): self
440440
{
441441
return $this->state(fn (Generator $faker, array $definition) => [
442442
'user' => UserFactory::new()->createOne(), // or makeOne to allow cascade persisting

docs/pages/services/seeders.mdx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
1-
# Database Seeders
1+
import {Callout} from "nextra-theme-docs";
2+
3+
## Introduction
4+
5+
Laravel includes the ability to seed your database with data using seed classes. All seed classes are stored in the database/seeders directory.
6+
Same as in Laravel with Eloquent, you can use default Laravel seeders to seed your data into the database, by using CycleORM database factories.
7+
8+
<Callout type="info" emoji="💡">
9+
Check also [Laravel Database Seeders](https://laravel.com/docs/10.x/seeding) documentation.
10+
</Callout>
11+
12+
## ✏️ Writing Seeders
13+
14+
Seeder classes are generated, same as it is in Laravel, using the `make:seeder` Artisan command. These classes are stored in the database/seeders directory. Seeder classes may have any name you wish, but probably should follow some sensible convention, such as `PostSeeder`, `CommentSeeder`, `UserSeeder` etc.
15+
16+
```bash
17+
php artisan make:seeder PostSeeder
18+
```
19+
20+
## ⚡️ Using Entity Factories
21+
22+
Best way to use seeders is to use Entity Factories, which is provided by [wayofdev/laravel-cycle-orm-factories](https://github.com/wayofdev/laravel-cycle-orm-factories). You can create a factory for each of your entities and use them to seed your database.
23+
24+
In this documentation section we will use examples from [Factories](/services/factories) documentation page.
25+
26+
For example, let's create 20 posts and 10 comments for each post:
27+
28+
```php
29+
<?php
30+
31+
namespace Database\Seeders;
32+
33+
use Illuminate\Database\Seeder;
34+
use Database\Factories\Post\PostFactory;
35+
use Database\Factories\Post\Comment\CommentFactory;
36+
use Database\Factories\User\UserFactory;
37+
38+
final class PostSeeder extends Seeder
39+
{
40+
public function run(): void
41+
{
42+
$author = UserFactory::new()->createOne();
43+
$posts = PostFactory::new()->withUser($author)->times(20)->create();
44+
45+
$collection->each(function (Post $post): void {
46+
CommentFactory::new([
47+
'post' => $post,
48+
])->times(10)->create();
49+
});
50+
}
51+
}
52+
```

docs/pages/usage/console-commands.mdx

Lines changed: 105 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,115 @@
1-
# Console Commands
1+
import {Callout} from "nextra-theme-docs";
22

33
This package includes CycleORM commands implemented as Laravel Console Commands, you can use them to manage your database schema and perform migrations.
44

5-
The package extends Laravel's artisan commands, introducing a set of commands specifically designed for managing Cycle ORM migrations and database schema. These commands are intuitive for Laravel developers and follow the framework's conventions.
5+
The package extends Laravel's artisan commands, introducing a set of commands specifically designed for managing CycleORM migrations and database schema. These commands are intuitive for Laravel developers and follow the framework's conventions.
66

77

88
## 🛠️ Commands for Migrations
99

10-
The package includes a set of commands for managing migrations. These commands are similar to Laravel's migration commands, but they are designed to work with Cycle ORM.
10+
Migration commands are essential for managing your database's evolution over time. They allow for the creation, execution, rollback, and status checking of migrations.
1111

12-
### Table of Contents
12+
### Command List
1313

14-
| Command | Description |
15-
|--------------------------|-----------------------------------------------------------------------------------------------------------------|
16-
| `cycle:migrate` | Executes pending migrations. Use the --one flag to execute only the first pending migration. |
17-
| `cycle:migrate:replay` | Replays migrations by rolling them back and then re-applying them. Use the --all flag to replay all migrations. |
18-
| `cycle:migrate:rollback` | Rolls back the last batch of migrations by default. Use the --all flag to roll back all migrations. |
19-
| `cycle:migrate:init` | Initializes the migration system by creating the necessary migrations table. |
20-
| `cycle:migrate:status` | Displays the status of all migrations, indicating which have been applied. |
21-
| `cycle:migrate:fresh` | Drops all tables and re-runs all migrations, providing a clean slate. ⚠️ |
14+
| Command | Description |
15+
|--------------------------|-------------------------------------------------------------------------------------------------------------------|
16+
| `cycle:migrate:init` | Initializes the migration system by creating the necessary migrations table. |
17+
| `cycle:migrate` | Executes pending migrations. Use the `--one` flag to execute only the first pending migration. |
18+
| `cycle:migrate:replay` | Replays migrations by rolling them back and then re-applying them. Use the `--all` flag to replay all migrations. |
19+
| `cycle:migrate:rollback` | Rolls back the last batch of migrations by default. Use the `--all` flag to roll back all migrations. |
20+
| `cycle:migrate:status` | Displays the status of all migrations, indicating which have been applied. |
21+
| `cycle:migrate:fresh` | Drops all tables and re-runs all migrations, providing a clean slate. ⚠️ |
2222

23-
### Usage
23+
### Initializing Migrations
24+
25+
`cycle:migrate:init`
26+
27+
This command is your starting point for migration management. It initializes the migration system by creating the necessary migrations table in your database, ensuring that you can start tracking and executing migrations.
28+
29+
#### Usage:
30+
31+
```bash
32+
php artisan cycle:migrate:init
33+
```
34+
35+
### Running Migrations
36+
37+
`cycle:migrate`
38+
39+
To apply pending migrations to your database, use the `cycle:migrate` command. This will execute all migrations that have not yet been applied, updating your database schema accordingly.
40+
41+
#### Usage:
42+
43+
```bash
44+
php artisan cycle:migrate
45+
```
46+
47+
#### Options:
48+
49+
`--one`: Executes only the first pending migration, allowing for more granular control over the migration process.
50+
51+
### Replaying Migrations
52+
53+
`cycle:migrate:replay`
54+
55+
This command facilitates the replaying of migrations by first rolling them back and then re-applying them. It's particularly useful for development environments where you need to quickly test changes to migrations.
56+
57+
#### Usage:
58+
59+
```bash
60+
php artisan cycle:migrate:replay
61+
```
62+
63+
#### Options:
64+
65+
`--all`: Replays all migrations, effectively refreshing your entire database schema.
66+
67+
68+
### Rolling Back Migrations
69+
70+
`cycle:migrate:rollback`
71+
72+
To undo the last batch of migrations, you can use the `cycle:migrate:rollback` command. This is useful when you need to revert changes made by the most recent migrations.
73+
74+
#### Usage:
75+
76+
```bash
77+
php artisan cycle:migrate:rollback
78+
```
79+
80+
#### Options:
81+
82+
`--all`: Rolls back all migrations, allowing you to revert your database schema to its initial state.
83+
84+
85+
### Checking Migration Status
86+
87+
`cycle:migrate:status`
88+
89+
Keeping track of which migrations have been applied is crucial for database management. The `cycle:migrate:status` command displays the status of all migrations, indicating which have been applied and which are pending.
90+
91+
#### Usage:
92+
93+
```bash
94+
php artisan cycle:migrate:status
95+
```
96+
97+
### Fresh Schema Command
98+
99+
`cycle:migrate:fresh`
100+
101+
When you need to start from a clean slate, the `cycle:migrate:fresh` command drops all tables from the database and re-runs all migrations. This is particularly useful for resetting the database to a known state during development or testing.
102+
103+
#### Usage:
104+
105+
```bash
106+
php artisan cycle:migrate:fresh
107+
```
108+
109+
<Callout type="warning" emoji="⚠️">
110+
Be cautious when using the `cycle:migrate:fresh` command, as it will permanently delete all data in your database.
111+
</Callout>
112+
113+
#### Options:
114+
115+
`--seed`: Seeds the database after running the migrations, populating it with initial data.

0 commit comments

Comments
 (0)