code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
protected function usingRealPath() { return $this->input->hasOption('realpath') && $this->option('realpath'); }
Determine if the given path(s) are pre-resolved "real" paths. @return bool
usingRealPath
php
illuminate/database
Console/Migrations/BaseCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/BaseCommand.php
MIT
protected function getMigrationPath() { return $this->laravel->databasePath().DIRECTORY_SEPARATOR.'migrations'; }
Get the path to the migration directory. @return string
getMigrationPath
php
illuminate/database
Console/Migrations/BaseCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/BaseCommand.php
MIT
public function __construct(Migrator $migrator) { parent::__construct(); $this->migrator = $migrator; }
Create a new fresh command instance. @param \Illuminate\Database\Migrations\Migrator $migrator
__construct
php
illuminate/database
Console/Migrations/FreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/FreshCommand.php
MIT
public function handle() { if ($this->isProhibited() || ! $this->confirmToProceed()) { return Command::FAILURE; } $database = $this->input->getOption('database'); $this->migrator->usingConnection($database, function () use ($database) { if ($this->migrator->repositoryExists()) { $this->newLine(); $this->components->task('Dropping all tables', fn () => $this->callSilent('db:wipe', array_filter([ '--database' => $database, '--drop-views' => $this->option('drop-views'), '--drop-types' => $this->option('drop-types'), '--force' => true, ])) == 0); } }); $this->newLine(); $this->call('migrate', array_filter([ '--database' => $database, '--path' => $this->input->getOption('path'), '--realpath' => $this->input->getOption('realpath'), '--schema-path' => $this->input->getOption('schema-path'), '--force' => true, '--step' => $this->option('step'), ])); if ($this->laravel->bound(Dispatcher::class)) { $this->laravel[Dispatcher::class]->dispatch( new DatabaseRefreshed($database, $this->needsSeeding()) ); } if ($this->needsSeeding()) { $this->runSeeder($database); } return 0; }
Execute the console command. @return int
handle
php
illuminate/database
Console/Migrations/FreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/FreshCommand.php
MIT
protected function needsSeeding() { return $this->option('seed') || $this->option('seeder'); }
Determine if the developer has requested database seeding. @return bool
needsSeeding
php
illuminate/database
Console/Migrations/FreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/FreshCommand.php
MIT
protected function runSeeder($database) { $this->call('db:seed', array_filter([ '--database' => $database, '--class' => $this->option('seeder') ?: 'Database\\Seeders\\DatabaseSeeder', '--force' => true, ])); }
Run the database seeder command. @param string $database @return void
runSeeder
php
illuminate/database
Console/Migrations/FreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/FreshCommand.php
MIT
protected function getOptions() { return [ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], ['drop-views', null, InputOption::VALUE_NONE, 'Drop all tables and views'], ['drop-types', null, InputOption::VALUE_NONE, 'Drop all tables and types (Postgres only)'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'], ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], ['schema-path', null, InputOption::VALUE_OPTIONAL, 'The path to a schema dump file'], ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run'], ['seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder'], ['step', null, InputOption::VALUE_NONE, 'Force the migrations to be run so they can be rolled back individually'], ]; }
Get the console command options. @return array
getOptions
php
illuminate/database
Console/Migrations/FreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/FreshCommand.php
MIT
public function __construct(MigrationRepositoryInterface $repository) { parent::__construct(); $this->repository = $repository; }
Create a new migration install command instance. @param \Illuminate\Database\Migrations\MigrationRepositoryInterface $repository
__construct
php
illuminate/database
Console/Migrations/InstallCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/InstallCommand.php
MIT
public function handle() { $this->repository->setSource($this->input->getOption('database')); if (! $this->repository->repositoryExists()) { $this->repository->createRepository(); } $this->components->info('Migration table created successfully.'); }
Execute the console command. @return void
handle
php
illuminate/database
Console/Migrations/InstallCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/InstallCommand.php
MIT
protected function getOptions() { return [ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], ]; }
Get the console command options. @return array
getOptions
php
illuminate/database
Console/Migrations/InstallCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/InstallCommand.php
MIT
public function __construct(Migrator $migrator, Dispatcher $dispatcher) { parent::__construct(); $this->migrator = $migrator; $this->dispatcher = $dispatcher; }
Create a new migration command instance. @param \Illuminate\Database\Migrations\Migrator $migrator @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
__construct
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
public function handle() { if (! $this->confirmToProceed()) { return 1; } try { $this->runMigrations(); } catch (Throwable $e) { if ($this->option('graceful')) { $this->components->warn($e->getMessage()); return 0; } throw $e; } return 0; }
Execute the console command. @return int
handle
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function runMigrations() { $this->migrator->usingConnection($this->option('database'), function () { $this->prepareDatabase(); // Next, we will check to see if a path option has been defined. If it has // we will use the path relative to the root of this installation folder // so that migrations may be run for any path within the applications. $this->migrator->setOutput($this->output) ->run($this->getMigrationPaths(), [ 'pretend' => $this->option('pretend'), 'step' => $this->option('step'), ]); // Finally, if the "seed" option has been given, we will re-run the database // seed task to re-populate the database, which is convenient when adding // a migration and a seed at the same time, as it is only this command. if ($this->option('seed') && ! $this->option('pretend')) { $this->call('db:seed', [ '--class' => $this->option('seeder') ?: 'Database\\Seeders\\DatabaseSeeder', '--force' => true, ]); } }); }
Run the pending migrations. @return void
runMigrations
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function prepareDatabase() { if (! $this->repositoryExists()) { $this->components->info('Preparing database.'); $this->components->task('Creating migration table', function () { return $this->callSilent('migrate:install', array_filter([ '--database' => $this->option('database'), ])) == 0; }); $this->newLine(); } if (! $this->migrator->hasRunAnyMigrations() && ! $this->option('pretend')) { $this->loadSchemaState(); } }
Prepare the migration database for running. @return void
prepareDatabase
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function repositoryExists() { return retry(2, fn () => $this->migrator->repositoryExists(), 0, function ($e) { try { return $this->handleMissingDatabase($e->getPrevious()); } catch (Throwable) { return false; } }); }
Determine if the migrator repository exists. @return bool
repositoryExists
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function handleMissingDatabase(Throwable $e) { if ($e instanceof SQLiteDatabaseDoesNotExistException) { return $this->createMissingSqliteDatabase($e->path); } $connection = $this->migrator->resolveConnection($this->option('database')); if (! $e instanceof PDOException) { return false; } if (($e->getCode() === 1049 && in_array($connection->getDriverName(), ['mysql', 'mariadb'])) || (($e->errorInfo[0] ?? null) == '08006' && $connection->getDriverName() == 'pgsql' && Str::contains($e->getMessage(), '"'.$connection->getDatabaseName().'"'))) { return $this->createMissingMySqlOrPgsqlDatabase($connection); } return false; }
Attempt to create the database if it is missing. @param \Throwable $e @return bool
handleMissingDatabase
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function createMissingSqliteDatabase($path) { if ($this->option('force')) { return touch($path); } if ($this->option('no-interaction')) { return false; } $this->components->warn('The SQLite database configured for this application does not exist: '.$path); if (! confirm('Would you like to create it?', default: true)) { $this->components->info('Operation cancelled. No database was created.'); throw new RuntimeException('Database was not created. Aborting migration.'); } return touch($path); }
Create a missing SQLite database. @param string $path @return bool @throws \RuntimeException
createMissingSqliteDatabase
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function createMissingMySqlOrPgsqlDatabase($connection) { if ($this->laravel['config']->get("database.connections.{$connection->getName()}.database") !== $connection->getDatabaseName()) { return false; } if (! $this->option('force') && $this->option('no-interaction')) { return false; } if (! $this->option('force') && ! $this->option('no-interaction')) { $this->components->warn("The database '{$connection->getDatabaseName()}' does not exist on the '{$connection->getName()}' connection."); if (! confirm('Would you like to create it?', default: true)) { $this->components->info('Operation cancelled. No database was created.'); throw new RuntimeException('Database was not created. Aborting migration.'); } } try { $this->laravel['config']->set( "database.connections.{$connection->getName()}.database", match ($connection->getDriverName()) { 'mysql', 'mariadb' => null, 'pgsql' => 'postgres', }, ); $this->laravel['db']->purge(); $freshConnection = $this->migrator->resolveConnection($this->option('database')); return tap($freshConnection->unprepared( match ($connection->getDriverName()) { 'mysql', 'mariadb' => "CREATE DATABASE IF NOT EXISTS `{$connection->getDatabaseName()}`", 'pgsql' => 'CREATE DATABASE "'.$connection->getDatabaseName().'"', } ), function () { $this->laravel['db']->purge(); }); } finally { $this->laravel['config']->set("database.connections.{$connection->getName()}.database", $connection->getDatabaseName()); } }
Create a missing MySQL or Postgres database. @param \Illuminate\Database\Connection $connection @return bool @throws \RuntimeException
createMissingMySqlOrPgsqlDatabase
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function loadSchemaState() { $connection = $this->migrator->resolveConnection($this->option('database')); // First, we will make sure that the connection supports schema loading and that // the schema file exists before we proceed any further. If not, we will just // continue with the standard migration operation as normal without errors. if ($connection instanceof SqlServerConnection || ! is_file($path = $this->schemaPath($connection))) { return; } $this->components->info('Loading stored database schemas.'); $this->components->task($path, function () use ($connection, $path) { // Since the schema file will create the "migrations" table and reload it to its // proper state, we need to delete it here so we don't get an error that this // table already exists when the stored database schema file gets executed. $this->migrator->deleteRepository(); $connection->getSchemaState()->handleOutputUsing(function ($type, $buffer) { $this->output->write($buffer); })->load($path); }); $this->newLine(); // Finally, we will fire an event that this schema has been loaded so developers // can perform any post schema load tasks that are necessary in listeners for // this event, which may seed the database tables with some necessary data. $this->dispatcher->dispatch( new SchemaLoaded($connection, $path) ); }
Load the schema state to seed the initial database schema structure. @return void
loadSchemaState
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
protected function schemaPath($connection) { if ($this->option('schema-path')) { return $this->option('schema-path'); } if (file_exists($path = database_path('schema/'.$connection->getName().'-schema.dump'))) { return $path; } return database_path('schema/'.$connection->getName().'-schema.sql'); }
Get the path to the stored schema for the given connection. @param \Illuminate\Database\Connection $connection @return string
schemaPath
php
illuminate/database
Console/Migrations/MigrateCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateCommand.php
MIT
public function __construct(MigrationCreator $creator, Composer $composer) { parent::__construct(); $this->creator = $creator; $this->composer = $composer; }
Create a new migration install command instance. @param \Illuminate\Database\Migrations\MigrationCreator $creator @param \Illuminate\Support\Composer $composer
__construct
php
illuminate/database
Console/Migrations/MigrateMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateMakeCommand.php
MIT
public function handle() { // It's possible for the developer to specify the tables to modify in this // schema operation. The developer may also specify if this table needs // to be freshly created so we can create the appropriate migrations. $name = Str::snake(trim($this->input->getArgument('name'))); $table = $this->input->getOption('table'); $create = $this->input->getOption('create') ?: false; // If no table was given as an option but a create option is given then we // will use the "create" option as the table name. This allows the devs // to pass a table name into this option as a short-cut for creating. if (! $table && is_string($create)) { $table = $create; $create = true; } // Next, we will attempt to guess the table name if this the migration has // "create" in the name. This will allow us to provide a convenient way // of creating migrations that create new tables for the application. if (! $table) { [$table, $create] = TableGuesser::guess($name); } // Now we are ready to write the migration out to disk. Once we've written // the migration out, we will dump-autoload for the entire framework to // make sure that the migrations are registered by the class loaders. $this->writeMigration($name, $table, $create); }
Execute the console command. @return void
handle
php
illuminate/database
Console/Migrations/MigrateMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateMakeCommand.php
MIT
protected function writeMigration($name, $table, $create) { $file = $this->creator->create( $name, $this->getMigrationPath(), $table, $create ); $this->components->info(sprintf('Migration [%s] created successfully.', $file)); }
Write the migration file to disk. @param string $name @param string $table @param bool $create @return void
writeMigration
php
illuminate/database
Console/Migrations/MigrateMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateMakeCommand.php
MIT
protected function getMigrationPath() { if (! is_null($targetPath = $this->input->getOption('path'))) { return ! $this->usingRealPath() ? $this->laravel->basePath().'/'.$targetPath : $targetPath; } return parent::getMigrationPath(); }
Get migration path (either specified by '--path' option or default location). @return string
getMigrationPath
php
illuminate/database
Console/Migrations/MigrateMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateMakeCommand.php
MIT
protected function promptForMissingArgumentsUsing() { return [ 'name' => ['What should the migration be named?', 'E.g. create_flights_table'], ]; }
Prompt for missing input arguments using the returned questions. @return array
promptForMissingArgumentsUsing
php
illuminate/database
Console/Migrations/MigrateMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/MigrateMakeCommand.php
MIT
public function handle() { if ($this->isProhibited() || ! $this->confirmToProceed()) { return Command::FAILURE; } // Next we'll gather some of the options so that we can have the right options // to pass to the commands. This includes options such as which database to // use and the path to use for the migration. Then we'll run the command. $database = $this->input->getOption('database'); $path = $this->input->getOption('path'); // If the "step" option is specified it means we only want to rollback a small // number of migrations before migrating again. For example, the user might // only rollback and remigrate the latest four migrations instead of all. $step = $this->input->getOption('step') ?: 0; if ($step > 0) { $this->runRollback($database, $path, $step); } else { $this->runReset($database, $path); } // The refresh command is essentially just a brief aggregate of a few other of // the migration commands and just provides a convenient wrapper to execute // them in succession. We'll also see if we need to re-seed the database. $this->call('migrate', array_filter([ '--database' => $database, '--path' => $path, '--realpath' => $this->input->getOption('realpath'), '--force' => true, ])); if ($this->laravel->bound(Dispatcher::class)) { $this->laravel[Dispatcher::class]->dispatch( new DatabaseRefreshed($database, $this->needsSeeding()) ); } if ($this->needsSeeding()) { $this->runSeeder($database); } return 0; }
Execute the console command. @return int
handle
php
illuminate/database
Console/Migrations/RefreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RefreshCommand.php
MIT
protected function runRollback($database, $path, $step) { $this->call('migrate:rollback', array_filter([ '--database' => $database, '--path' => $path, '--realpath' => $this->input->getOption('realpath'), '--step' => $step, '--force' => true, ])); }
Run the rollback command. @param string $database @param string $path @param int $step @return void
runRollback
php
illuminate/database
Console/Migrations/RefreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RefreshCommand.php
MIT
protected function runReset($database, $path) { $this->call('migrate:reset', array_filter([ '--database' => $database, '--path' => $path, '--realpath' => $this->input->getOption('realpath'), '--force' => true, ])); }
Run the reset command. @param string $database @param string $path @return void
runReset
php
illuminate/database
Console/Migrations/RefreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RefreshCommand.php
MIT
protected function needsSeeding() { return $this->option('seed') || $this->option('seeder'); }
Determine if the developer has requested database seeding. @return bool
needsSeeding
php
illuminate/database
Console/Migrations/RefreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RefreshCommand.php
MIT
protected function runSeeder($database) { $this->call('db:seed', array_filter([ '--database' => $database, '--class' => $this->option('seeder') ?: 'Database\\Seeders\\DatabaseSeeder', '--force' => true, ])); }
Run the database seeder command. @param string $database @return void
runSeeder
php
illuminate/database
Console/Migrations/RefreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RefreshCommand.php
MIT
protected function getOptions() { return [ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'], ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], ['seed', null, InputOption::VALUE_NONE, 'Indicates if the seed task should be re-run'], ['seeder', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder'], ['step', null, InputOption::VALUE_OPTIONAL, 'The number of migrations to be reverted & re-run'], ]; }
Get the console command options. @return array
getOptions
php
illuminate/database
Console/Migrations/RefreshCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RefreshCommand.php
MIT
public function __construct(Migrator $migrator) { parent::__construct(); $this->migrator = $migrator; }
Create a new migration rollback command instance. @param \Illuminate\Database\Migrations\Migrator $migrator
__construct
php
illuminate/database
Console/Migrations/ResetCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/ResetCommand.php
MIT
public function handle() { if ($this->isProhibited() || ! $this->confirmToProceed()) { return Command::FAILURE; } return $this->migrator->usingConnection($this->option('database'), function () { // First, we'll make sure that the migration table actually exists before we // start trying to rollback and re-run all of the migrations. If it's not // present we'll just bail out with an info message for the developers. if (! $this->migrator->repositoryExists()) { return $this->components->warn('Migration table not found.'); } $this->migrator->setOutput($this->output)->reset( $this->getMigrationPaths(), $this->option('pretend') ); }); }
Execute the console command. @return int
handle
php
illuminate/database
Console/Migrations/ResetCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/ResetCommand.php
MIT
protected function getOptions() { return [ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'], ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run'], ]; }
Get the console command options. @return array
getOptions
php
illuminate/database
Console/Migrations/ResetCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/ResetCommand.php
MIT
public function __construct(Migrator $migrator) { parent::__construct(); $this->migrator = $migrator; }
Create a new migration rollback command instance. @param \Illuminate\Database\Migrations\Migrator $migrator
__construct
php
illuminate/database
Console/Migrations/RollbackCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RollbackCommand.php
MIT
public function handle() { if ($this->isProhibited() || ! $this->confirmToProceed()) { return Command::FAILURE; } $this->migrator->usingConnection($this->option('database'), function () { $this->migrator->setOutput($this->output)->rollback( $this->getMigrationPaths(), [ 'pretend' => $this->option('pretend'), 'step' => (int) $this->option('step'), 'batch' => (int) $this->option('batch'), ] ); }); return 0; }
Execute the console command. @return int
handle
php
illuminate/database
Console/Migrations/RollbackCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RollbackCommand.php
MIT
protected function getOptions() { return [ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to be executed'], ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], ['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run'], ['step', null, InputOption::VALUE_OPTIONAL, 'The number of migrations to be reverted'], ['batch', null, InputOption::VALUE_REQUIRED, 'The batch of migrations (identified by their batch number) to be reverted'], ]; }
Get the console command options. @return array
getOptions
php
illuminate/database
Console/Migrations/RollbackCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/RollbackCommand.php
MIT
public function __construct(Migrator $migrator) { parent::__construct(); $this->migrator = $migrator; }
Create a new migration rollback command instance. @param \Illuminate\Database\Migrations\Migrator $migrator
__construct
php
illuminate/database
Console/Migrations/StatusCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/StatusCommand.php
MIT
public function handle() { return $this->migrator->usingConnection($this->option('database'), function () { if (! $this->migrator->repositoryExists()) { $this->components->error('Migration table not found.'); return 1; } $ran = $this->migrator->getRepository()->getRan(); $batches = $this->migrator->getRepository()->getMigrationBatches(); $migrations = $this->getStatusFor($ran, $batches) ->when($this->option('pending') !== false, fn ($collection) => $collection->filter(function ($migration) { return (new Stringable($migration[1]))->contains('Pending'); })); if (count($migrations) > 0) { $this->newLine(); $this->components->twoColumnDetail('<fg=gray>Migration name</>', '<fg=gray>Batch / Status</>'); $migrations ->each( fn ($migration) => $this->components->twoColumnDetail($migration[0], $migration[1]) ); $this->newLine(); } elseif ($this->option('pending') !== false) { $this->components->info('No pending migrations'); } else { $this->components->info('No migrations found'); } if ($this->option('pending') && $migrations->some(fn ($m) => (new Stringable($m[1]))->contains('Pending'))) { return $this->option('pending'); } }); }
Execute the console command. @return int|null
handle
php
illuminate/database
Console/Migrations/StatusCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/StatusCommand.php
MIT
protected function getStatusFor(array $ran, array $batches) { return (new Collection($this->getAllMigrationFiles())) ->map(function ($migration) use ($ran, $batches) { $migrationName = $this->migrator->getMigrationName($migration); $status = in_array($migrationName, $ran) ? '<fg=green;options=bold>Ran</>' : '<fg=yellow;options=bold>Pending</>'; if (in_array($migrationName, $ran)) { $status = '['.$batches[$migrationName].'] '.$status; } return [$migrationName, $status]; }); }
Get the status for the given run migrations. @param array $ran @param array $batches @return \Illuminate\Support\Collection
getStatusFor
php
illuminate/database
Console/Migrations/StatusCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/StatusCommand.php
MIT
protected function getAllMigrationFiles() { return $this->migrator->getMigrationFiles($this->getMigrationPaths()); }
Get an array of all of the migration files. @return array
getAllMigrationFiles
php
illuminate/database
Console/Migrations/StatusCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/StatusCommand.php
MIT
protected function getOptions() { return [ ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], ['pending', null, InputOption::VALUE_OPTIONAL, 'Only list pending migrations', false], ['path', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'The path(s) to the migrations files to use'], ['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths'], ]; }
Get the console command options. @return array
getOptions
php
illuminate/database
Console/Migrations/StatusCommand.php
https://github.com/illuminate/database/blob/master/Console/Migrations/StatusCommand.php
MIT
public static function guess($migration) { foreach (self::CREATE_PATTERNS as $pattern) { if (preg_match($pattern, $migration, $matches)) { return [$matches[1], $create = true]; } } foreach (self::CHANGE_PATTERNS as $pattern) { if (preg_match($pattern, $migration, $matches)) { return [$matches[2], $create = false]; } } }
Attempt to guess the table name and "creation" status of the given migration. @param string $migration @return array
guess
php
illuminate/database
Console/Migrations/TableGuesser.php
https://github.com/illuminate/database/blob/master/Console/Migrations/TableGuesser.php
MIT
public function __construct(Resolver $resolver) { parent::__construct(); $this->resolver = $resolver; }
Create a new database seed command instance. @param \Illuminate\Database\ConnectionResolverInterface $resolver
__construct
php
illuminate/database
Console/Seeds/SeedCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeedCommand.php
MIT
public function handle() { if ($this->isProhibited() || ! $this->confirmToProceed()) { return Command::FAILURE; } $this->components->info('Seeding database.'); $previousConnection = $this->resolver->getDefaultConnection(); $this->resolver->setDefaultConnection($this->getDatabase()); Model::unguarded(function () { $this->getSeeder()->__invoke(); }); if ($previousConnection) { $this->resolver->setDefaultConnection($previousConnection); } return 0; }
Execute the console command. @return int
handle
php
illuminate/database
Console/Seeds/SeedCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeedCommand.php
MIT
protected function getSeeder() { $class = $this->input->getArgument('class') ?? $this->input->getOption('class'); if (! str_contains($class, '\\')) { $class = 'Database\\Seeders\\'.$class; } if ($class === 'Database\\Seeders\\DatabaseSeeder' && ! class_exists($class)) { $class = 'DatabaseSeeder'; } return $this->laravel->make($class) ->setContainer($this->laravel) ->setCommand($this); }
Get a seeder instance from the container. @return \Illuminate\Database\Seeder
getSeeder
php
illuminate/database
Console/Seeds/SeedCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeedCommand.php
MIT
protected function getDatabase() { $database = $this->input->getOption('database'); return $database ?: $this->laravel['config']['database.default']; }
Get the name of the database connection to use. @return string
getDatabase
php
illuminate/database
Console/Seeds/SeedCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeedCommand.php
MIT
protected function getArguments() { return [ ['class', InputArgument::OPTIONAL, 'The class name of the root seeder', null], ]; }
Get the console command arguments. @return array
getArguments
php
illuminate/database
Console/Seeds/SeedCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeedCommand.php
MIT
protected function getOptions() { return [ ['class', null, InputOption::VALUE_OPTIONAL, 'The class name of the root seeder', 'Database\\Seeders\\DatabaseSeeder'], ['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to seed'], ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], ]; }
Get the console command options. @return array
getOptions
php
illuminate/database
Console/Seeds/SeedCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeedCommand.php
MIT
public function handle() { parent::handle(); }
Execute the console command. @return void
handle
php
illuminate/database
Console/Seeds/SeederMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeederMakeCommand.php
MIT
protected function getStub() { return $this->resolveStubPath('/stubs/seeder.stub'); }
Get the stub file for the generator. @return string
getStub
php
illuminate/database
Console/Seeds/SeederMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeederMakeCommand.php
MIT
protected function resolveStubPath($stub) { return is_file($customPath = $this->laravel->basePath(trim($stub, '/'))) ? $customPath : __DIR__.$stub; }
Resolve the fully-qualified path to the stub. @param string $stub @return string
resolveStubPath
php
illuminate/database
Console/Seeds/SeederMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeederMakeCommand.php
MIT
protected function getPath($name) { $name = str_replace('\\', '/', Str::replaceFirst($this->rootNamespace(), '', $name)); if (is_dir($this->laravel->databasePath().'/seeds')) { return $this->laravel->databasePath().'/seeds/'.$name.'.php'; } return $this->laravel->databasePath().'/seeders/'.$name.'.php'; }
Get the destination class path. @param string $name @return string
getPath
php
illuminate/database
Console/Seeds/SeederMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeederMakeCommand.php
MIT
protected function rootNamespace() { return 'Database\Seeders\\'; }
Get the root namespace for the class. @return string
rootNamespace
php
illuminate/database
Console/Seeds/SeederMakeCommand.php
https://github.com/illuminate/database/blob/master/Console/Seeds/SeederMakeCommand.php
MIT
public function withoutModelEvents(callable $callback) { return fn () => Model::withoutEvents($callback); }
Prevent model events from being dispatched by the given callback. @param callable $callback @return callable
withoutModelEvents
php
illuminate/database
Console/Seeds/WithoutModelEvents.php
https://github.com/illuminate/database/blob/master/Console/Seeds/WithoutModelEvents.php
MIT
public function __construct($model, $event) { $this->model = $model; $this->event = $event; }
Create a new event instance. @param \Illuminate\Database\Eloquent\Model $model @param string $event
__construct
php
illuminate/database
Eloquent/BroadcastableModelEventOccurred.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastableModelEventOccurred.php
MIT
public function broadcastOn() { $channels = empty($this->channels) ? ($this->model->broadcastOn($this->event) ?: []) : $this->channels; return (new BaseCollection($channels)) ->map(fn ($channel) => $channel instanceof Model ? new PrivateChannel($channel) : $channel) ->all(); }
The channels the event should broadcast on. @return array
broadcastOn
php
illuminate/database
Eloquent/BroadcastableModelEventOccurred.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastableModelEventOccurred.php
MIT
public function broadcastAs() { $default = class_basename($this->model).ucfirst($this->event); return method_exists($this->model, 'broadcastAs') ? ($this->model->broadcastAs($this->event) ?: $default) : $default; }
The name the event should broadcast as. @return string
broadcastAs
php
illuminate/database
Eloquent/BroadcastableModelEventOccurred.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastableModelEventOccurred.php
MIT
public function broadcastWith() { return method_exists($this->model, 'broadcastWith') ? $this->model->broadcastWith($this->event) : null; }
Get the data that should be sent with the broadcasted event. @return array|null
broadcastWith
php
illuminate/database
Eloquent/BroadcastableModelEventOccurred.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastableModelEventOccurred.php
MIT
public function onChannels(array $channels) { $this->channels = $channels; return $this; }
Manually specify the channels the event should broadcast on. @param array $channels @return $this
onChannels
php
illuminate/database
Eloquent/BroadcastableModelEventOccurred.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastableModelEventOccurred.php
MIT
public function shouldBroadcastNow() { return $this->event === 'deleted' && ! method_exists($this->model, 'bootSoftDeletes'); }
Determine if the event should be broadcast synchronously. @return bool
shouldBroadcastNow
php
illuminate/database
Eloquent/BroadcastableModelEventOccurred.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastableModelEventOccurred.php
MIT
public function event() { return $this->event; }
Get the event name. @return string
event
php
illuminate/database
Eloquent/BroadcastableModelEventOccurred.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastableModelEventOccurred.php
MIT
public static function bootBroadcastsEvents() { static::created(function ($model) { $model->broadcastCreated(); }); static::updated(function ($model) { $model->broadcastUpdated(); }); if (method_exists(static::class, 'bootSoftDeletes')) { static::softDeleted(function ($model) { $model->broadcastTrashed(); }); static::restored(function ($model) { $model->broadcastRestored(); }); } static::deleted(function ($model) { $model->broadcastDeleted(); }); }
Boot the event broadcasting trait. @return void
bootBroadcastsEvents
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastCreated($channels = null) { return $this->broadcastIfBroadcastChannelsExistForEvent( $this->newBroadcastableModelEvent('created'), 'created', $channels ); }
Broadcast that the model was created. @param \Illuminate\Broadcasting\Channel|\Illuminate\Contracts\Broadcasting\HasBroadcastChannel|array|null $channels @return \Illuminate\Broadcasting\PendingBroadcast
broadcastCreated
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastUpdated($channels = null) { return $this->broadcastIfBroadcastChannelsExistForEvent( $this->newBroadcastableModelEvent('updated'), 'updated', $channels ); }
Broadcast that the model was updated. @param \Illuminate\Broadcasting\Channel|\Illuminate\Contracts\Broadcasting\HasBroadcastChannel|array|null $channels @return \Illuminate\Broadcasting\PendingBroadcast
broadcastUpdated
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastTrashed($channels = null) { return $this->broadcastIfBroadcastChannelsExistForEvent( $this->newBroadcastableModelEvent('trashed'), 'trashed', $channels ); }
Broadcast that the model was trashed. @param \Illuminate\Broadcasting\Channel|\Illuminate\Contracts\Broadcasting\HasBroadcastChannel|array|null $channels @return \Illuminate\Broadcasting\PendingBroadcast
broadcastTrashed
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastRestored($channels = null) { return $this->broadcastIfBroadcastChannelsExistForEvent( $this->newBroadcastableModelEvent('restored'), 'restored', $channels ); }
Broadcast that the model was restored. @param \Illuminate\Broadcasting\Channel|\Illuminate\Contracts\Broadcasting\HasBroadcastChannel|array|null $channels @return \Illuminate\Broadcasting\PendingBroadcast
broadcastRestored
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastDeleted($channels = null) { return $this->broadcastIfBroadcastChannelsExistForEvent( $this->newBroadcastableModelEvent('deleted'), 'deleted', $channels ); }
Broadcast that the model was deleted. @param \Illuminate\Broadcasting\Channel|\Illuminate\Contracts\Broadcasting\HasBroadcastChannel|array|null $channels @return \Illuminate\Broadcasting\PendingBroadcast
broadcastDeleted
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
protected function broadcastIfBroadcastChannelsExistForEvent($instance, $event, $channels = null) { if (! static::$isBroadcasting) { return; } if (! empty($this->broadcastOn($event)) || ! empty($channels)) { return broadcast($instance->onChannels(Arr::wrap($channels))); } }
Broadcast the given event instance if channels are configured for the model event. @param mixed $instance @param string $event @param mixed $channels @return \Illuminate\Broadcasting\PendingBroadcast|null
broadcastIfBroadcastChannelsExistForEvent
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function newBroadcastableModelEvent($event) { return tap($this->newBroadcastableEvent($event), function ($event) { $event->connection = property_exists($this, 'broadcastConnection') ? $this->broadcastConnection : $this->broadcastConnection(); $event->queue = property_exists($this, 'broadcastQueue') ? $this->broadcastQueue : $this->broadcastQueue(); $event->afterCommit = property_exists($this, 'broadcastAfterCommit') ? $this->broadcastAfterCommit : $this->broadcastAfterCommit(); }); }
Create a new broadcastable model event event. @param string $event @return mixed
newBroadcastableModelEvent
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
protected function newBroadcastableEvent(string $event) { return new BroadcastableModelEventOccurred($this, $event); }
Create a new broadcastable model event for the model. @param string $event @return \Illuminate\Database\Eloquent\BroadcastableModelEventOccurred
newBroadcastableEvent
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastOn($event) { return [$this]; }
Get the channels that model events should broadcast on. @param string $event @return \Illuminate\Broadcasting\Channel|array
broadcastOn
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastConnection() { // }
Get the queue connection that should be used to broadcast model events. @return string|null
broadcastConnection
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function broadcastQueue() { // }
Get the queue that should be used to broadcast model events. @return string|null
broadcastQueue
php
illuminate/database
Eloquent/BroadcastsEvents.php
https://github.com/illuminate/database/blob/master/Eloquent/BroadcastsEvents.php
MIT
public function __construct(QueryBuilder $query) { $this->query = $query; }
Create a new Eloquent query builder instance. @param \Illuminate\Database\Query\Builder $query
__construct
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function make(array $attributes = []) { return $this->newModelInstance($attributes); }
Create and return an un-saved model instance. @param array $attributes @return TModel
make
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function withGlobalScope($identifier, $scope) { $this->scopes[$identifier] = $scope; if (method_exists($scope, 'extend')) { $scope->extend($this); } return $this; }
Register a new global scope. @param string $identifier @param \Illuminate\Database\Eloquent\Scope|\Closure $scope @return $this
withGlobalScope
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function withoutGlobalScope($scope) { if (! is_string($scope)) { $scope = get_class($scope); } unset($this->scopes[$scope]); $this->removedScopes[] = $scope; return $this; }
Remove a registered global scope. @param \Illuminate\Database\Eloquent\Scope|string $scope @return $this
withoutGlobalScope
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function withoutGlobalScopes(?array $scopes = null) { if (! is_array($scopes)) { $scopes = array_keys($this->scopes); } foreach ($scopes as $scope) { $this->withoutGlobalScope($scope); } return $this; }
Remove all or passed registered global scopes. @param array|null $scopes @return $this
withoutGlobalScopes
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function removedScopes() { return $this->removedScopes; }
Get an array of global scopes that were removed from the query. @return array
removedScopes
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function whereKey($id) { if ($id instanceof Model) { $id = $id->getKey(); } if (is_array($id) || $id instanceof Arrayable) { if (in_array($this->model->getKeyType(), ['int', 'integer'])) { $this->query->whereIntegerInRaw($this->model->getQualifiedKeyName(), $id); } else { $this->query->whereIn($this->model->getQualifiedKeyName(), $id); } return $this; } if ($id !== null && $this->model->getKeyType() === 'string') { $id = (string) $id; } return $this->where($this->model->getQualifiedKeyName(), '=', $id); }
Add a where clause on the primary key to the query. @param mixed $id @return $this
whereKey
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function whereKeyNot($id) { if ($id instanceof Model) { $id = $id->getKey(); } if (is_array($id) || $id instanceof Arrayable) { if (in_array($this->model->getKeyType(), ['int', 'integer'])) { $this->query->whereIntegerNotInRaw($this->model->getQualifiedKeyName(), $id); } else { $this->query->whereNotIn($this->model->getQualifiedKeyName(), $id); } return $this; } if ($id !== null && $this->model->getKeyType() === 'string') { $id = (string) $id; } return $this->where($this->model->getQualifiedKeyName(), '!=', $id); }
Add a where clause on the primary key to the query. @param mixed $id @return $this
whereKeyNot
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function where($column, $operator = null, $value = null, $boolean = 'and') { if ($column instanceof Closure && is_null($operator)) { $column($query = $this->model->newQueryWithoutRelationships()); $this->eagerLoad = array_merge($this->eagerLoad, $query->getEagerLoads()); $this->withoutGlobalScopes( $query->removedScopes() ); $this->query->addNestedWhereQuery($query->getQuery(), $boolean); } else { $this->query->where(...func_get_args()); } return $this; }
Add a basic where clause to the query. @param (\Closure(static): mixed)|string|array|\Illuminate\Contracts\Database\Query\Expression $column @param mixed $operator @param mixed $value @param string $boolean @return $this
where
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function firstWhere($column, $operator = null, $value = null, $boolean = 'and') { return $this->where(...func_get_args())->first(); }
Add a basic where clause to the query, and return the first result. @param (\Closure(static): mixed)|string|array|\Illuminate\Contracts\Database\Query\Expression $column @param mixed $operator @param mixed $value @param string $boolean @return TModel|null
firstWhere
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function orWhere($column, $operator = null, $value = null) { [$value, $operator] = $this->query->prepareValueAndOperator( $value, $operator, func_num_args() === 2 ); return $this->where($column, $operator, $value, 'or'); }
Add an "or where" clause to the query. @param (\Closure(static): mixed)|array|string|\Illuminate\Contracts\Database\Query\Expression $column @param mixed $operator @param mixed $value @return $this
orWhere
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function whereNot($column, $operator = null, $value = null, $boolean = 'and') { return $this->where($column, $operator, $value, $boolean.' not'); }
Add a basic "where not" clause to the query. @param (\Closure(static): mixed)|string|array|\Illuminate\Contracts\Database\Query\Expression $column @param mixed $operator @param mixed $value @param string $boolean @return $this
whereNot
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function orWhereNot($column, $operator = null, $value = null) { return $this->whereNot($column, $operator, $value, 'or'); }
Add an "or where not" clause to the query. @param (\Closure(static): mixed)|array|string|\Illuminate\Contracts\Database\Query\Expression $column @param mixed $operator @param mixed $value @return $this
orWhereNot
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function latest($column = null) { if (is_null($column)) { $column = $this->model->getCreatedAtColumn() ?? 'created_at'; } $this->query->latest($column); return $this; }
Add an "order by" clause for a timestamp to the query. @param string|\Illuminate\Contracts\Database\Query\Expression $column @return $this
latest
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function oldest($column = null) { if (is_null($column)) { $column = $this->model->getCreatedAtColumn() ?? 'created_at'; } $this->query->oldest($column); return $this; }
Add an "order by" clause for a timestamp to the query. @param string|\Illuminate\Contracts\Database\Query\Expression $column @return $this
oldest
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function hydrate(array $items) { $instance = $this->newModelInstance(); return $instance->newCollection(array_map(function ($item) use ($items, $instance) { $model = $instance->newFromBuilder($item); if (count($items) > 1) { $model->preventsLazyLoading = Model::preventsLazyLoading(); } return $model; }, $items)); }
Create a collection of models from plain arrays. @param array $items @return \Illuminate\Database\Eloquent\Collection<int, TModel>
hydrate
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function fillAndInsert(array $values) { return $this->insert($this->fillForInsert($values)); }
Insert into the database after merging the model's default attributes, setting timestamps, and casting values. @param array<int, array<string, mixed>> $values @return bool
fillAndInsert
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function fillAndInsertOrIgnore(array $values) { return $this->insertOrIgnore($this->fillForInsert($values)); }
Insert (ignoring errors) into the database after merging the model's default attributes, setting timestamps, and casting values. @param array<int, array<string, mixed>> $values @return int
fillAndInsertOrIgnore
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function fillAndInsertGetId(array $values) { return $this->insertGetId($this->fillForInsert([$values])[0]); }
Insert a record into the database and get its ID after merging the model's default attributes, setting timestamps, and casting values. @param array<string, mixed> $values @return int
fillAndInsertGetId
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function fillForInsert(array $values) { if (empty($values)) { return []; } if (! is_array(reset($values))) { $values = [$values]; } $this->model->unguarded(function () use (&$values) { foreach ($values as $key => $rowValues) { $values[$key] = tap( $this->newModelInstance($rowValues), fn ($model) => $model->setUniqueIds() )->getAttributes(); } }); return $this->addTimestampsToUpsertValues($values); }
Enrich the given values by merging in the model's default attributes, adding timestamps, and casting values. @param array<int, array<string, mixed>> $values @return array<int, array<string, mixed>>
fillForInsert
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function fromQuery($query, $bindings = []) { return $this->hydrate( $this->query->getConnection()->select($query, $bindings) ); }
Create a collection of models from a raw query. @param string $query @param array $bindings @return \Illuminate\Database\Eloquent\Collection<int, TModel>
fromQuery
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function find($id, $columns = ['*']) { if (is_array($id) || $id instanceof Arrayable) { return $this->findMany($id, $columns); } return $this->whereKey($id)->first($columns); }
Find a model by its primary key. @param mixed $id @param array|string $columns @return ($id is (\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed>) ? \Illuminate\Database\Eloquent\Collection<int, TModel> : TModel|null)
find
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function findSole($id, $columns = ['*']) { return $this->whereKey($id)->sole($columns); }
Find a sole model by its primary key. @param mixed $id @param array|string $columns @return TModel @throws \Illuminate\Database\Eloquent\ModelNotFoundException<TModel> @throws \Illuminate\Database\MultipleRecordsFoundException
findSole
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function findMany($ids, $columns = ['*']) { $ids = $ids instanceof Arrayable ? $ids->toArray() : $ids; if (empty($ids)) { return $this->model->newCollection(); } return $this->whereKey($ids)->get($columns); }
Find multiple models by their primary keys. @param \Illuminate\Contracts\Support\Arrayable|array $ids @param array|string $columns @return \Illuminate\Database\Eloquent\Collection<int, TModel>
findMany
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function findOrFail($id, $columns = ['*']) { $result = $this->find($id, $columns); $id = $id instanceof Arrayable ? $id->toArray() : $id; if (is_array($id)) { if (count($result) !== count(array_unique($id))) { throw (new ModelNotFoundException)->setModel( get_class($this->model), array_diff($id, $result->modelKeys()) ); } return $result; } if (is_null($result)) { throw (new ModelNotFoundException)->setModel( get_class($this->model), $id ); } return $result; }
Find a model by its primary key or throw an exception. @param mixed $id @param array|string $columns @return ($id is (\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed>) ? \Illuminate\Database\Eloquent\Collection<int, TModel> : TModel) @throws \Illuminate\Database\Eloquent\ModelNotFoundException<TModel>
findOrFail
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT
public function findOrNew($id, $columns = ['*']) { if (! is_null($model = $this->find($id, $columns))) { return $model; } return $this->newModelInstance(); }
Find a model by its primary key or return fresh model instance. @param mixed $id @param array|string $columns @return ($id is (\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|array<mixed>) ? \Illuminate\Database\Eloquent\Collection<int, TModel> : TModel)
findOrNew
php
illuminate/database
Eloquent/Builder.php
https://github.com/illuminate/database/blob/master/Eloquent/Builder.php
MIT