Code:
    public function store(Request $request)
    {

        $data = $this->validate($request,[
            'name' => 'required|min:3',
            'email' => 'required|unique:users|email',
            'password' => 'required|min:5|confirmed'
        ]);
        $data['password'] = bcrypt($data['password']);
        User::create($data);

    }
用Laravel 自带的create添加数据时出错。

解决方法:
Just add use App\User before the class declaration - like this:
use App\User;
Or you can change your controller code to be \App\User::create(... (notice the \ at the beginning)

两个方法用其中一个就行了:
方法下:
Code:
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
class UserController extends Controller
{

...


public function store(Request $request) { $data = $this->validate($request,[ 'name' => 'required|min:3', 'email' => 'required|unique:users|email', 'password' => 'required|min:5|confirmed' ]); $data['password'] = bcrypt($data['password']); User::create($data); }


方法二:
Code:
    public function store(Request $request)
    {

        $data = $this->validate($request,[
            'name' => 'required|min:3',
            'email' => 'required|unique:users|email',
            'password' => 'required|min:5|confirmed'
        ]);
        $data['password'] = bcrypt($data['password']);
        \App\User::create($data);

    }