๐ค Dumper in Squehub
The Dumper system in Squehub helps you populate your database with test or fake data using clean PHP logic. It is useful for development, staging, demos, or local testing environments.
๐ Directory Structure
All Dumper classes must be created inside the database/dumper/
directory.
Each Dumper must extend the base class App\Core\Dumper
.
database/
โโโ dumper/
โโโ UsersDumper.php
๐งฉ Example Dumper File
This example generates 10 users using the User
model.
<?php
namespace Database\Dumper;
use App\Core\Dumper; // โ
Always required
use Project\Models\User; // โ
Only needed if interacting with the User model
class UsersDumper extends Dumper
{
public function run()
{
for ($i = 1; $i <= 10; $i++) {
User::create([
'name' => "User $i",
'username' => "user$i",
'email' => "user$i@example.com",
'password' => password_hash("password", PASSWORD_DEFAULT),
'country' => 'USA',
'status' => 'active',
]);
}
}
}
๐ Running a Dumper
To run your Dumper class from the CLI:
$ php squehub dump:run UsersDumper
This will call the run()
method and insert the data.
โก Generate One Automatically
You can use the CLI to scaffold a new Dumper file:
$ php squehub make:Dumper UsersDumper
This creates a file under database/dumper/
with the correct structure.
๐ Important Notes
- โ
Always include
use App\Core\Dumper;
at the top โ it powers the Dumper system. - โ
Only include
use Project\Models\XYZ;
when the dumper interacts with that model (e.g.User
). - ๐ง All Dumper classes must have a valid
namespace
โ e.g.namespace Database\Dumper;
. - ๐งช Dumper files are for inserting fake/test data into real database tables.
- ๐ Keep logic simple: create one dumper per dataset type (users, products, orders, etc).
โ Summary
- ๐ Dumper files live in
database/dumper/
. - ๐งฑ They must extend
App\Core\Dumper
. - ๐ฆ Use model classes like
use Project\Models\User;
only when needed. - ๐ The
run()
method contains the data-insertion logic. - ๐ป Run with:
php squehub dump:run YourDumperName
.
๐ก Tip: You can also group related Dumper files under subdirectories inside
database/dumper/
. Just
ensure the namespace reflects the folder structure.