Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Seeds From Sql

Seeds From Sql Laravel Package

christian-schoenefeld/seeds-from-sql

Laravel package demonstrating how to seed a database from a .sql file. Includes an SQLSeeder that imports SQL using DB::unprepared; run via php artisan db:seed --class=SQLSeeder (after migrate) or as part of DatabaseSeeder.

View on GitHub
Deep Wiki
Context7

This package shows different approaches to using seeds from a sql file.

Frequently asked questions about Seeds From Sql
How do I install and set up `seeds-from-sql` in my Laravel project?
Run `composer require christian-schoenefeld/seeds-from-sql`, then register the `SQLSeeder` class in your `DatabaseSeeder`'s `run()` method. No additional configuration is needed unless you customize the SQL file path.
Can I use this package to seed a production database with large SQL dumps?
Yes, but test performance first. The package uses `DB::unprepared()` for raw SQL execution, which may impact speed or memory usage. Consider batching large imports or running them outside peak hours.
Does this package support Laravel 10+ and PHP 8.1+?
Yes, the package is compatible with Laravel 10 and PHP 8.1+. It leverages Laravel’s built-in `DB` facade, which is fully supported in these versions. Always check the package’s `composer.json` for minor version constraints.
Is there a risk of SQL injection when using `DB::unprepared()`?
Yes, raw SQL execution via `DB::unprepared()` is vulnerable to injection if the SQL file contains user-provided or untrusted input. Only use this for trusted, static SQL files or sanitize inputs rigorously.
How do I run only the SQL seeder without executing all seeders?
Use the Artisan command `php artisan db:seed --class=SQLSeeder`. This bypasses other seeders and executes only the SQL seeder defined in the package.
Can I customize the path or name of the SQL file used for seeding?
Currently, the package defaults to a predefined SQL file path. To customize it, you’d need to extend the `SQLSeeder` class or modify the package’s source code directly, as there’s no built-in configuration option.
Will this package work with PostgreSQL, MySQL, or SQLite?
The package should work with any database Laravel supports, but raw SQL syntax (e.g., `ENGINE=InnoDB`) may not be portable. Test your SQL file across target databases to ensure compatibility.
Are there alternatives to this package for seeding from SQL files?
Yes, alternatives include manually using `DB::statement()` or `DB::unprepared()` in a custom seeder, or packages like `laravel-seed-dump` for generating seeders from existing databases. This package simplifies the process by providing a dedicated seeder class.
How do I handle transactions or rollbacks when seeding with SQL?
The package doesn’t automatically wrap SQL execution in transactions. For rollback support, wrap the `SQLSeeder` call in a transaction block in your `DatabaseSeeder` using `DB::transaction()`.
Does this package trigger Laravel model events (e.g., `created`, `saved`) during SQL imports?
No, raw SQL execution via `DB::unprepared()` bypasses Eloquent’s event system. If you rely on model events, consider using Eloquent-based seeders or factories instead.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle