Not enough arguments missing name when i make seed Laravel - php

i am trying to make a seed with:
php artisan make:seed
But, i get the error:
Not enough arguments (missing: "name").
I dont know why, this is the seed i am trying to make:
class ProfessionSeeder extends Seeder
{
public function run()
{
DB::table('professions')->insert([
'title' => 'Desarrollador Back End'
]);
}
}
This is the migration corresponding to the DB table...
class CreateProfessionsTable extends Migration
{
public function up()
{
Schema::create('professions', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title', 100);
$table->timestamps();
});
}
Any ideas of what is going on?
Thank you!

You can see what is required for a command by using artisan help:
php artisan help make:seed
Will output something like:
Description:
Create a new seeder class
Usage:
make:seeder <name>
Arguments:
name The name of the class
...
This command takes an argument for the name of the class you want to create.
php artisan make:seed ProfessionSeeder

Related

Laravel: How to create migration file for drop multiple columns from a table?

When I drop a column, I use following command to create migration file,
php artisan make:migration drop_institue_id_column_from_providers
And migration file:
public function up()
{
Schema::table('providers', function(Blueprint $table) {
$table->dropColumn('institue_id');
});
}
public function down()
{
Schema::table('providers', function (Blueprint $table)
{
$table->integer('institue_id')->unsigned();
});
}
If I want to drop multiple columns, I can write migration file this way,
public function up()
{
Schema::table('providers', function(Blueprint $table) {
$table->dropColumn('institue_id');
$table->dropColumn('institue_name');
$table->dropColumn('institue_address');
});
}
public function down()
{
Schema::table('providers', function (Blueprint $table)
{
$table->integer('institue_id')->unsigned();
$table->char('institue_name');
$table->char('institue_address');
});
}
But What is the command to create that migration file? Thank you.
I assume this is just a question about naming convention for the migration class.
If so then it does not matter what the file\class is called, as long as it gives you a good idea of what it does.
So it could be something like:
php artisan make:migration drop_institue_columns_from_providers
When you execute the php artisan make:migration command, it just create a class in which you can specific what migration you can do. You can do many modification for one table, even for many table. So just put all your code in one migration file will be OK.
To create a migration file run:
php artisan make: migration your_migration_file_name_here
and then you can drop multiple columns by passing an array
Schema::table('providers', function(Blueprint $table) {
$table->dropColumn('institue_id', 'institue_name', 'institue_address');
});

Want to add column but migration class is not found even It exists

I am learning Laravel.
Here is my migration file code.
class CreatePostTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('post', function (Blueprint $table) {
$table->increments('id');
$table->integer('user_id')->unsigned(); // i want to add this column after adding this line i runs the command refresh but it shows below errors.
$table->string('title');
$table->text('body');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('post');
}
}
Now I have a problem that whenever I run this command in terminal in PhpStorm:
php artisan migrate:refresh
it shows following errors:
PHP Fatal error: Class 'AddIsAdminColumnToPostTable' not found in C:\xampp\htdocs\cms\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php on line 335
Symfony\Component\Debug\Exception\FatalErrorException]
Class 'AddIsAdminColumnToPostTable' not found
I tried composer dump-autoload in terminal solution from here but it's not working. I also used rollback command but still having issue.
How can make refresh this?
Artisan looks for migrations based on the file name. If you want it to be called something else: rollback, delete the migration, make a new migration. Or, change the file name to exactly match the class name.
For you, try changing
class CreatePostTable extends Migration
to
class AddIsAdminColumnToPostTable extends Migration

Laravel 5.3 Seeder - undefined method table?

I'm trying to learn Laravel, but it seems the documentation is written with faulty examples... I want to create a table migration, run it, and seed it with some content.
First:
php artisan make:migration create_projects_and_tasks_tables
With the following content:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProjectsAndTasksTables extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('projects', function (Blueprint $table) {
$table->increments('id');
$table->string('name')->default('');
$table->string('slug')->default('');
$table->timestamps();
});
Schema::create('tasks', function (Blueprint $table) {
$table->increments('id');
$table->integer('project_id')->unsigned()->default(0);
$table->foreign('project_id')->references('id')->on('projects')->onDelete('cascade');
$table->string('name')->default('');
$table->string('slug')->default('');
$table->boolean('completed')->default(false);
$table->text('description');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('tasks');
Schema::drop('projects');
}
}
It migrated Ok. So I want to seed the projects table.
First:
php artisan make:seeder ProjectsTableSeeder
The contents:
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class ProjectsTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
$projects = array(
['id' => 1, 'name' => 'Project 1', 'slug' => 'project-1', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['id' => 2, 'name' => 'Project 2', 'slug' => 'project-2', 'created_at' => new DateTime, 'updated_at' => new DateTime],
['id' => 3, 'name' => 'Project 3', 'slug' => 'project-3', 'created_at' => new DateTime, 'updated_at' => new DateTime]
);
DB::table('projects')->insert($projects);
}
}
All set, I tried to rollback the migration, migrate and seed it:
php artisan migrate:refresh --seed
Rolled back: 2016_09_28_160459_create_projects_and_tasks_tables
Rolled back: 2014_10_12_100000_create_password_resets_table
Rolled back: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2016_09_28_160459_create_projects_and_tasks_tables
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Illuminate\Database\MySqlConnection::setTable()
And that's it. My table is empty, and the method DB::table() seems to not exist anymore in the framework, even if the 5.3 docs shows it. What can I do?
I'm using the Laravel Homestead vagrant box, so php version or composer isn't the issue. I'm also using MySQL as my database driver.
Once you have written your seeder classes, you may use the db:seed Artisan command to seed your database. By default, the db:seed command runs the DatabaseSeeder class, which may be used to call other seed classes. However, you may use the --class option to specify a specific seeder class to run individually:
php artisan db:seed
php artisan db:seed --class=UsersTableSeeder
Also You Can provide a seeder class reference to call method of DatabaseSeeder.php file
php artisan db:seed
will run the DatabaseSeeder.php file and invoke the run() meothd
So here you can provide list of Seed source like follow
public function run()
{
$this->call(CountriesTableSeeder::class);
$this->call(VendorTypesTableSeeder::class);
}
Reference : seeding
By default, the --seed option when passed to the migrate:refresh command will run
{YOUR_APP}/database/seeds/DatabaseSeeder.php
The make:migration artisan command will create your seed, but it won't add the seeder to the DatabaseSeeder.php file. You'll need to manually do this.
However, if you want to specify a particular seeder with migrate:refresh, then use the --seeder=YourSeeder option.
Add the following to the top of your seeder class:
use Illuminate\Support\Facades\DB;
Somehow, DB is not within the scope.
I got the exact same error. This was caused by typo obviously. Try to compare all the dataseed tables with other tables. You might have put \DB::class instead of \DB::table.

Why does php artisan migrate nothing?

Running "php artisan migrate" does nothing: no database modifications, no message(olso no "nothing to migrate"), no error.
No records are being added to table migrations as well.
Previously, the command "php artisan migrate" was working fine.
One of the migration files in folder database/migrations has this content:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class VidsTableEdit14 extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('vids', function(Blueprint $table)
{
//
$table->integer('test');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('vids', function(Blueprint $table)
{
//
});
}
}
How to make "php artisan migrate" working?
If the migration stops working suddenly there is probably a syntax error somewhere in one of your migrations. If you suddenly get a class not found error be suspicious of a syntax error.
This same happened me, when I was trying to add soft delete to my table.
I created the migration and in the Schema::table function I typed "$table->softDelete();". Instead of
$table->softDeletes();
Notice the 's' for plural, I tried running migration and didn't get any error or message. I made it plural and it worked.
And I noticed that you didn't make down function().Try adding:
Schema::drop('vids');
And run the migration again.
Error:
SQLSTATE[42S01]
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException
-------------
[php artisan migrate]
Solution: Go to:
app\Http\Providers\AppServiceProvider
import ( use Illuminate\Support\Facades\Schema; )
And, inside the register() function, insert this code:
public function register()
{
Schema::defaultStringLength(191);
}
Then run:
php artisan migrate:fresh

Laravel 4 Migration Error

I'm getting the following error when trying to create migrations for my laravel 4 installation. The file gets created but it outputs the following error.
Created Migration: 2014_07_06_073213_create-users-table
Generating optimized class loader
Compiling common classes
{"error":
{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'ClassPreloader\\Command\\PreCompileCommand' not found","file":"\/home\/name123\/domain.com\/laravel\/vendor\/laravel\/framework\/src\/Illuminate\/Foundation\/Console\/OptimizeCommand.php","line":113}}[warehouse]
$ php artisan migrate:make create-users-table
It doesn't seem that there are any other people having the same problem.
Also getting this error when i commit the migration
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to a member function increments() on a non-object","file":"\/home\/dandel26\/danieldelcore.com\/laravel\/app\/database\/migrations\/2014_06_29_092641_create_users_table.php","line":15}}
Thanks in advance.
In you're migration you have the function up. In this function there will be something like:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
});
It would seem that you did not do define the callback with the variable $table. Please add Blueprint $table and it should work.
In that case remember to import the right namespaces:
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

Categories