未找到基表或视图:1146表'Vojodb.users'不存在

时间:2018-05-07 16:45:06

标签: php mysql laravel authentication orm

我喜欢将数据保存到数据库。但它显示错误 SQLSTATE [42S02]:未找到基表或视图:1146表'vojodb.users'不存在(SQL:插入users **我在stackoverflow中搜索了如何解决了我的问题。我曾尝试在用户模型中添加** public $ table =“users”。但没有任何反应。请给我解决方案如何解决此问题。

这是我的代码

//注册控制器

<?php

namespace App\Http\Controllers\Auth;

use App\Models\User;
use App\Models\Band;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
use Session;
use File;

class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/

use RegistersUsers;

/**
 * Where to redirect users after registration.
 *
 * @var string
 */
protected $redirectTo = '/home';

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('guest');
}

/**
 * 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|string|max:255',
        'email' => 'required|string|email|max:255|unique:users',
        'password' => 'required|string|min:6|confirmed',
    ]);
}

/**
 * Create a new user instance after a valid registration.
 *
 * @param  array  $data
 * @return \App\User
 */
protected function create(array $data, Request $request)
{

}
protected function show(){
    return view('auth.register');
}

protected function savesession(Request $request){
    Session::put('SimpanNamaBand',$request->input('senderName'));
    Session::put('SimpanEmailBand',$request->input('senderEmail'));
    Session::put('SimpanUserBand',$request->input('senderUsername'));
    Session::put('SimpanPasswordBand',$request->input('senderPassword'));


}
protected function savesessiondua(Request $request){
    Session::put('SimpanKotaBand',$request->input('senderCity'));
    Session::put('SimpanTanggalBand',$request->input('senderFormedDate'));
    Session::put('SimpanGenreBand',$request->input('senderGenre'));
    Session::put('SimpanWebsiteBand',$request->input('senderWebsite'));
    Session::put('SimpanContactBand',$request->input('senderContact'));


}

protected function lastsession(Request $request)
{
    Session::put('SimpanTypeBand', $request->input('soundsLike'));
}

protected function showform(){

    return view('auth.registertwo');
    //return view('auth.registerv');
}
protected function showformfinal(){
    //$print = Session::get('SaveRegister');
    return view('auth.final');
    //return view('auth.registerv');
}

protected function showformverification(){
    return view('auth.verify');
}

protected function test(){
    if(Session::has('SimpanNamaBand')){
        $value = Session::get('SimpanNamaBand');
        var_dump($value);
    }
}
protected function store(Request $request){
    $user = new User;
    $user->username = Session::get('SimpanUserBand');
    $user->password = bcrypt(Session::get('SimpanPasswordBand'));
    $user->email = Session::get('SimpanEmailBand');
    $user->name = Session::get('SimpanNamaBand');
    $user->user_type = 'band';

    $user->save();

    $band = new Band;
    $band->city = Session::get('SimpanCityBand');
    $band->formed_date = Session::get('SimpanTanggalBand');
    $band->genre = Session::get('SimpanGenreBand');
    $band->website = Session::get('SimpanWebsiteBand');
    $band->contact = Session::get('SimpanContactBand');
    $band->sounds_like = Session::get('SimpanTypeBand');

    if(!$request->hasFile('verify_file') && !$request->file('verify_file')->isValid()) {
        return abort(404, 'File not uploaded!');
    }

    $filename = $request->session()->get('SimpanNamaBand');
    $request->image->move(base_path('public/' .$request->session()->get("SimpanNamaBan"). '/document'), $filename);


    $band->verification_file = $filename;
    $band->save();
    return response()->json(['Data berhasil di simpan']);

}
}

//用户迁移

<?php

use Illuminate\Support\Facades\Schema;
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('username');
        $table->string('password');
        $table->string('email')->unique();
        $table->string('name');
        $table->enum('user_type', ['customer', 'band', 'admin'])->default('customer');
        $table->string('profile_picture')->nullable();
        $table->datetime('last_login')->nullable();
        $table->rememberToken();
        $table->timestamps();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::dropIfExists('users');
}
}

//用户模型

<?php

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
use Notifiable;

/**
 * The attributes that are mass assignable.
 *
 * @var array
 */
protected $fillable = [
    'name', 'email', 'password','username'
];

/**
 * The attributes that should be hidden for arrays.
 *
 * @var array
 */
protected $hidden = [
    'password', 'remember_token',
];

protected $table = "users";

// Ambil data dari field yang bersangkutan
public function detail() {
    return $this->hasOne('App\Models\\'.ucfirst($this->user_type));
}
}

//乐队模型

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Band extends Model
{
protected $primaryKey = 'user_id';
public $incrementing  = false;

public function user() {
    return $this->belongsTo(User::class);
}
}

我使用了 php artisan make:auth ,但我根据需要修改了控制器。是否可能导致错误?谢谢。

2 个答案:

答案 0 :(得分:0)

我知道这可能听起来很简单,但你在运行迁移后检查了数据库中的表吗?它甚至存在吗?

答案 1 :(得分:0)

解决方案非常简单 可能您的查询中有一个小错误 例如:

INSERT INTO”。$ tableName错误

INSERT INTO“。$ tableName ..是真的

非常简单