SQLSTATE[42S02]: 未找到基础 table 或视图:1146 Table 'db.store' 不存在

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.store' doesn't exist

当我尝试将数据从 laravel 表单保存到数据库时 table 我收到以下异常:

SQLSTATE[42S02]:未找到基础 table 或视图:1146 Table 'db.store' 不存在(SQL: select count(*) 作为来自 store 的聚合,其中 name = samplename)

table 商店存在,但我仍然收到错误

这是我正在处理表格的控制器:

 <?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    use App\storestore;
    use App\Http\Requests\storeFormRequest;



    class AddstoreController extends Controller
    {
        //

        public function create()
        {
            //

        }

        public function store( storeFormRequest $request)
        {

            $store = new Store;
            $store->name = Input::get('name');
            $store->description = Input::get('description');
            $store->store_vendor_id = Input::get('owner');
            $store->contact_email = Input::get('contact_email');
            $store->postal_address = Input::get('postal_address');
            $store->city = Input::get('city');
            $store->zip = Input::get('zip');
            $store->phone = Input::get('phone');
            $store->business_logo = Input::get('logo');
            $store->save();
            return \Redirect::route('add_store_success')
          ->with('message', 'Thanks for joining us!');
        }
    }

这是我的 商店 型号:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Store extends Model
{
    //

    protected $table = 'stores';

     protected $fillable = ['name', 'description', 'vendor_id',
     'contact_email','postal_address','city','zip','phone',
     'meta_description','business_logo'];

 }

存储请求文件:

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

use App\StoreController;


class StoreFormRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
    'name' => 'required|unique:dstore',
    'vendor_id' => 'required',
    'contact_email' => 'required|email|max:100|unique:dstore',

    'business_logo' => 'required',

        ];

         //validate
        if ($validation->fails())
        {
            return redirect()->back()->withErrors($v->errors());
        }

    }


}

这些是 getpost 路线:

Route::get('/store_form', ['as' => 'add_store_form', 'uses' => 'StoreController@create']);
Route::post('/store_form',['as' => 'dstore', 'uses' => 'StoreController@store']);

当我 运行 php artisan route:list 命令

我试图寻找解决方案,但我找到的解决方案指出缺少 tables 作为一门课程,但在我的情况下,商店 table 存在但我仍然得到错误。

请帮忙!

看看你的 Store 型号 class:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Store extends Model
{
    //

    protected $table = 'stores';

     protected $fillable = ['name', 'description', 'vendor_id',
     'contact_email','postal_address','city','zip','phone',
     'meta_description','business_logo'];

}

如您所见,属性 $table 设置为 stores 所以我假设 table 数据库中的名称是 stores 而不是 store.

您可能应该更改 StoreFormRequest 内容或 rules 方法以在 unique 规则中使用有效 table 名称,例如:

public function rules()
{
    return [
        //
'name' => 'required|unique:stores',
'vendor_id' => 'required',
'contact_email' => 'required|email|max:100|unique:stores',

'business_logo' => 'required',

    ];

     //validate
    if ($validation->fails())
    {
        return redirect()->back()->withErrors($v->errors());
    }

}