I'm trying to make following tutorial: https://medium.com/on-coding/e8d93c9ce0e2
When it comes to run:
php artisan migrate
I get following error:
[Exception]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.user' doesn't
exist (SQL: alter table `user` add `id` int unsigned not null auto_increment prim
ary key, add `username` varchar(255) null, add `password` varchar(255) null, add
`email` varchar(255) null, add `created_at` datetime null, add `updated_at` datet
ime null) (Bindings: array (
))
Database connection is working, the migrations table was created successfully. Database name was changed as you can see in the error message.
Whats quite strange to me, is that it tries to alter the table - which doesn't exists - and not to create it.
Here are my other files, like UserModel, Seeder, Migtation and DB Config.
CreateUserTable:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUserTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('user', function(Blueprint $table)
{
$table->increments("id");
$table
->string("username")
->nullable()
->default(null);
$table
->string("password")
->nullable()
->default(null);
$table
->string("email")
->nullable()
->default(null);
$table
->dateTime("created_at")
->nullable()
->default(null);
$table
->dateTime("updated_at")
->nullable()
->default(null);
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('user', function(Blueprint $table)
{
Schema::dropIfExists("user");
});
}
}
UserModel:
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'user';
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = array('password');
/**
* Get the unique identifier for the user.
*
* #return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the password for the user.
*
* #return string
*/
public function getAuthPassword()
{
return $this->password;
}
/**
* Get the e-mail address where password reminders are sent.
*
* #return string
*/
public function getReminderEmail()
{
return $this->email;
}
}
UserSeeder:
class UserSeeder extends DatabaseSeeder
{
public function run()
{
$users = [
[
"username" => "ihkawiss",
"password" => Hash::make("123456"),
"email" => "ihkawiss#domain.com"
]
];
foreach ($users as $user)
{
User::create($user);
}
}
}
DatabaseSeeder:
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
Eloquent::unguard();
$this->call('UserSeeder');
}
}
Database Config:
return array(
/*
|--------------------------------------------------------------------------
| PDO Fetch Style
|--------------------------------------------------------------------------
|
| By default, database results will be returned as instances of the PHP
| stdClass object; however, you may desire to retrieve records in an
| array format for simplicity. Here you can tweak the fetch style.
|
*/
'fetch' => PDO::FETCH_CLASS,
/*
|--------------------------------------------------------------------------
| Default Database Connection Name
|--------------------------------------------------------------------------
|
| Here you may specify which of the database connections below you wish
| to use as your default connection for all database work. Of course
| you may use many connections at once using the Database library.
|
*/
'default' => 'mysql',
/*
|--------------------------------------------------------------------------
| Database Connections
|--------------------------------------------------------------------------
|
| Here are each of the database connections setup for your application.
| Of course, examples of configuring each database platform that is
| supported by Laravel is shown below to make development simple.
|
|
| All database work in Laravel is done through the PHP PDO facilities
| so make sure you have the driver for your particular database of
| choice installed on your machine before you begin development.
|
*/
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'laravel',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'prefix' => '',
),
),
/*
|--------------------------------------------------------------------------
| Migration Repository Table
|--------------------------------------------------------------------------
|
| This table keeps track of all the migrations that have already run for
| your application. Using this information, we can determine which of
| the migrations on disk have not actually be run in the databases.
|
*/
'migrations' => 'migrations',
/*
|--------------------------------------------------------------------------
| Redis Databases
|--------------------------------------------------------------------------
|
| Redis is an open source, fast, and advanced key-value store that also
| provides a richer set of commands than a typical key-value systems
| such as APC or Memcached. Laravel makes it easy to dig right in.
|
*/
'redis' => array(
'cluster' => true,
'default' => array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
),
),
);
Hope somebody can give me a hint here.
Best regards ihkawiss
In your CreateUserTable migration file, instead of Schema::table you have to use Schema::create.
The Schema::table is used to alter an existing table and the Schema::create is used to create new table.
Check the documentation:
http://laravel.com/docs/schema#creating-and-dropping-tables
http://laravel.com/docs/schema#adding-columns
So your user migration will be:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUserTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('user', function(Blueprint $table) {
{
$table->increments("id",true);
$table->string("username")->nullable()->default(null);
$table->string("password")->nullable()->default(null);
$table->string("email")->nullable()->default(null);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists("user");
}
}
The underlying cause of this may be if the syntax used for creating the migration php artisan migrate ... is not quite correct. In this case the --create will not get picked up properly and you will see the Schema::table instead of the expected Schema::create. When a migration file is generated like this you might also be missing some of the other markers for a create migration such as the $table->increments('id'); and $table->timestamps();
For example, these two commands will not create a create table migration file as you might expect:
php artisan migrate:make create_tasks_table --table="tasks" --create
php artisan migrate:make create_tasks2_table --table=tasks2 --create
However, the command will not fail with an error. Instead laravel will create a migration file using Schema::table
I always just use the full syntax when creating a new migration file like this:
php artisan migrate:make create_tasks_table --table=tasks --create=tasks
to avoid any issues like this.
Sometimes it is caused by custom artisan commands. Some of these commands might initiate few classes. And because we did a rollback, the table cannot be found. Check you custom artisan commands. You can comment out the lines which are causing the trigger. Run the php artisan migrate command and then uncomment. This is what I had to do.
Related
I started to develop the Laravel + VueJS dashboard application. But I have a problem with security.
When I enter this URL http://127.0.0.1:8000/api/user without log in I seeing request answer.
I started researching the Internet to find a solution to the problem. As a result of my research, I found the Laravel Passport. I set it up as described on the official page, but I didn't succeed. But the application is constantly responding. {"message":"Unauthenticated."}
UserController.php
<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function __construct()
{
$this->middleware('auth:api');
}
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return User::latest()->paginate(100);
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//return['message'=>'I have data'];
//return $request->all();
$this->validate($request,[
'name' => 'required|string|max:191',
'email' => 'required|string|email|max:191|unique:users',
'password' => 'required|string|min:6'
]);
return User::create([
'name' => $request['name'],
'email' => $request['email'],
'type' => $request['type'],
'bio' => $request['bio'],
'photo' => $request['photo'],
'password' => Hash::make($request['password']),
]);
}
public function profile()
{
return auth('api')->user();
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$user = User::findOrFail($id);
$this->validate($request,[
'name' => 'required|string|max:191',
'email' => 'required|string|email|max:191|unique:users,email,'.$user->id,
'password' => 'sometimes|min:6'
]);
$user->update($request->all());
return ['message' => 'update'];
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$user = User::findOrFail($id);
$user->delete();
return['message' => 'User Deleted'];
}
}
auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Authentication Defaults
|--------------------------------------------------------------------------
|
| This option controls the default authentication "guard" and password
| reset options for your application. You may change these defaults
| as required, but they're a perfect start for most applications.
|
*/
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
/*
|--------------------------------------------------------------------------
| Authentication Guards
|--------------------------------------------------------------------------
|
| Next, you may define every authentication guard for your application.
| Of course, a great default configuration has been defined for you
| here which uses session storage and the Eloquent user provider.
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| Supported: "session", "token"
|
*/
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'api' => [
'driver' => 'passport',
'provider' => 'users',
'hash' => false,
],
],
/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
/*
|--------------------------------------------------------------------------
| Resetting Passwords
|--------------------------------------------------------------------------
|
| You may specify multiple password reset configurations if you have more
| than one user table or model in the application and you want to have
| separate password reset settings based on the specific user types.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
/*
|--------------------------------------------------------------------------
| Password Confirmation Timeout
|--------------------------------------------------------------------------
|
| Here you may define the amount of seconds before a password confirmation
| times out and the user is prompted to re-enter their password via the
| confirmation screen. By default, the timeout lasts for three hours.
|
*/
'password_timeout' => 10800,
];
AuthServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Laravel\Passport\Passport;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* #var array
*/
protected $policies = [
'App\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* #return void
*/
public function boot()
{
$this->registerPolicies();
Passport::routes();
Passport::personalAccessTokensExpireIn(now()->addDays(1));
//
}
}
User.php
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Passport\HasApiTokens;
class User extends Authenticatable
{
use HasFactory, Notifiable, HasApiTokens;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'email', 'password', 'bio', 'photo', 'type'
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
Request Syntax
axios.get("api/user").then(({ data }) => (this.users = data.data));
From my research, I think everything seems right. But I'm making my improvements with Wamp server on Windows. Do you think that's going to be a problem? Do I need to make settings on the htaccess file like this?
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Add the Authorization header with Bearer [your token] to the request and send it again, then check if it still returns Unauthenticated.
I added the following lines to Kernel.php and my problem was resolved.
Kernel.php
'web' => [
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],
I recently changed the way my application connects to my PostgreSQL database to add the read/write principle. Since then, when I launch a migration I get the following error:
In Connection.php line 463:
[PDOException (42601)]
SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """"
LINE 1: create table "" ("id" serial primary key not null, "migratio...
^
when I delete the database.php file, my migrations work correctly.
My .env
DB_CONNECTION=pgsql
DB_HOST=192.168.1.1
DB_PORT=5432
DB_DATABASE=database
DB_USERNAME=user
DB_PASSWORD=password
DB_USERNAME_READ=user
DB_PASSWORD_READ=password
My database.php
<?php
return [
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'pgsql' => [
'read' => [
'username' => env('DB_USERNAME_READ'),
'password' => env('DB_PASSWORD_READ'),
],
'write' => [
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
],
'sticky' => true,
'driver' => 'pgsql',
'host' => env('DB_HOST'),
'database' => env('DB_DATABASE'),
],
],
];
and one of my migrations:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateGameUserTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('game_user', function (Blueprint $table) {
$table->bigInteger('game_id');
$table->bigInteger('user_id');
$table->foreign('game_id')->references('id')->on('games');
$table->foreign('user_id')->references('id')->on('users');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('game_user');
}
}
PHP 7.3.13
Lumen 6.3.3
PostegreSQL 9.6.2
Lumen doesn't come with a config/database.php file by default. You can either copy a default Laravel file, or create your own with your own settings.
If you've already added your own custom file, it looks like you need to specify the migrations table name.
Default entry for Laravel is 'migrations' => 'migrations', but of course you can name it whatever you like.
I got the same problem on a Laravel 7.x project.
My solution was to remove the cache of my application then to update my dependencies via composer:
php artisan cache:clear
composer update
In Laravel, I have a table of articles which I pulled from a database at the start of my project over a month ago.
This database is separate from my Laravel application but the content may change daily and I've been manually grabbing the content every three days, which as you can imagine takes time.
I've seen that you can have two database connects in Laravel, like so:
<?php
return array(
'default' => 'mysql',
'connections' => array(
# Our primary database connection
'mysql' => array(
'driver' => 'mysql',
'host' => 'host1',
'database' => 'database1',
'username' => 'user1',
'password' => 'pass1'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
# Our secondary database connection
'mysql2' => array(
'driver' => 'mysql',
'host' => 'host2',
'database' => 'database2',
'username' => 'user2',
'password' => 'pass2'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
);
So, If I have my secondary article table that I can connect to is it possible to create a cron job that pulls in new content to my Laravel application every hour?
When pulling from the secondary database, how could I avoid overwriting content?
You can define a model for the secondary database like this
namespace App\Secondary;
class Article extends Model {
protected $connection = 'mysql2';
public static function fetchArticles(){
//fetch articles
//TODO all other filter to fetch new records
$articles = Article::all();
return $articles;
}
}
How to avoid overwrite content?
if you have id or any identity column in both primary and secondary connection db table then just fetch the latest article id from primary connection article table and fetch new articles after that id from secondary db table.
Here is the scheduler class
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ArticlePuller extends Command
{
/**
* The name and signature of the console command.
*
* #var string
*/
protected $signature = 'articlePuller';
/**
* The console command description.
*
* #var string
*/
protected $description = 'Pull article from secondary database';
/**
* Execute the console command.
*
* #return mixed
*/
public function handle()
{
$articles = Secondary/Article::fetchArticles(); //from secondary db table
Article::insertArticles($articles);
}
}
Define this scheduler in console/Kernel.php
protected $commands = [
Commands\ArticlePuller::class
];
protected function schedule(Schedule $schedule)
{
$schedule->command('articlePuller')->hourly();
}
Now need to add this scheduler entry in cron job
* * * * * php path_to_artisan/artisan schedule:run >> /dev/null 2>&1
I am trying to migrate my postgresql table, but when launch the command php artisan migrate it return the follow error:
SQLSTATE[08P01]: <>: 7 ERROR: bind message supplies 1 parameters, but prepared statement "pdo_stmt_00000003" requires 2 (SQL: select * from information_schema.tables
where table_schema = migrations and table_name = ?)
One of my migration:
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSchedulesTable extends Migration {
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('schedules', function(Blueprint $table)
{
$table->increments('id');
$table->string('schedule_name')->unique();
$table->integer('parent_id')->unsigned()->nullable();
$table->integer('launch_sequence_id')->unsigned();
$table->string('day_of_week', 10)->nullable();
$table->string('command_type', 50);
$table->integer('hours')->unsigned()->nullable();
$table->integer('minutes')->unsigned()->nullable();
$table->integer('dd')->unsigned()->nullable();
$table->integer('mm')->unsigned()->nullable();
$table->integer('yyyy')->unsigned()->nullable();
$table->boolean('enabled')->default(1);
$table->boolean('ascending')->default(0);
$table->dateTime('last_execution')->nullable();
$table->dateTime('last_success')->nullable();
$table->integer('retry')->default(0);
$table->timestamps();
$table->softDeletes();
});
DB::statement('ALTER TABLE schedules ADD CONSTRAINT day_of_week_check CHECK ((day_of_week)::text = ANY (ARRAY[(\'all\'::character varying)::text, (\'monday\'::character varying)::text, (\'tuesday\'::character varying)::text, (\'wednesday\'::character varying)::text, (\'thursday\'::character varying)::text, (\'friday\'::character varying)::text, (\'saturday\'::character varying)::text, (\'sunday\'::character varying)::text]))');
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('schedules');
}
}
And my database configuration:
'default' => env('DB_CONNECTION', 'pgsql'),
'connections' => [
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => env('DB_SCHEMA', 'public'),
//'sslmode' => 'prefer',
]
],
My .env
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=livion
DB_USERNAME=livion
DB_PASSWORD=secret
DB_SCHEMA=public
I tried to track it down and seems that it doesn't use the correct grammar for the function repositoryExists, it uses the default grammar witch doesn't send the schema parameter.
The other query executed via model or repository works fine, I get this error only for the migration command.
Any suggestion to solve this problem?
I figure out the problem.
I migrated the project from laravel 5.3 to 5.5 and the old project used the module Aejnsn\Postgresify.
It causes my problem on migration.
Remove it and all works again.
I have a fresh new larval project and configured like official documentation. I am trying to make an Authentication but I am getting an error:
1/2 PDOException in Connection.php line 381: SQLSTATE[42S22]: Column
not found: 1054 Unknown column 'name' in 'field list'
second error:
2/2 QueryException in Connection.php line 636: SQLSTATE[42S22]: Column
not found: 1054 Unknown column 'name' in 'field list' (SQL: insert
into users (name, email, password, updated_at, created_at)
values (test, test#test.de,
yyZbWechqvYF9a/qxMCUpuc4svE2.wwoD4KzBEaTZh/idIZwDE9Iq, 2015-08-02
19:23:26, 2015-08-02 19:23:26))
Here is my code:
(same as larval official Docs)
auth.php
<?php
return [
/*
|--------------------------------------------------------------------------
| Default Authentication Driver
|--------------------------------------------------------------------------
|
| This option controls the authentication driver that will be utilized.
| This driver manages the retrieval and authentication of the users
| attempting to get access to protected areas of your application.
|
| Supported: "database", "eloquent"
|
*/
'driver' => 'eloquent',
/*
|--------------------------------------------------------------------------
| Authentication Model
|--------------------------------------------------------------------------
|
| When using the "Eloquent" authentication driver, we need to know which
| Eloquent model should be used to retrieve your users. Of course, it
| is often just the "User" model but you may use whatever you like.
|
*/
'model' => App\User::class,
/*
|--------------------------------------------------------------------------
| Authentication Table
|--------------------------------------------------------------------------
|
| When using the "Database" authentication driver, we need to know which
| table should be used to retrieve your users. We have chosen a basic
| default value but you may easily change it to any table you like.
|
*/
'table' => 'users',
/*
|--------------------------------------------------------------------------
| Password Reset Settings
|--------------------------------------------------------------------------
|
| Here you may set the options for resetting passwords including the view
| that is your password reset e-mail. You can also set the name of the
| table that maintains all of the reset tokens for your application.
|
| The expire time is the number of minutes that the reset token should be
| considered valid. This security feature keeps tokens short-lived so
| they have less time to be guessed. You may change this as needed.
|
*/
'password' => [
'email' => 'emails.password',
'table' => 'password_resets',
'expire' => 60,
],
];
User.php:
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword;
/**
* The database table used by the model.
*
* #var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* #var array
*/
protected $hidden = ['password', 'remember_token'];
}
AuthControllor.php:
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
protected $redirectPath = '/dashboard';
protected $loginPath = '/login';
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
migration:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}
Hope you can help me!