我用artisan co创建了一个带有迁移文件的模型 and php artisan make:model Staff -m 在迁移文件中创建了两个表
Schema::create('staffcat', function (Blueprint $table) {
});
Schema::create('staff', function (Blueprint $table) {
});
现在尝试通过以下方式将数据从StaffController存储到staffcat表中 存储方法。但这没有找到人员表:(
I created another model Staffcat. But no luck :( Create_staff_table File
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateStaffTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('staffcat', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('catname');
});
Schema::create('staff', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('user_id');
$table->string('name');
$table->string('designaton');
$table->string('nid')->nullable();
$table->date('dob');
$table->date('doj');
$table->string('blood')->nullable();
$table->string('mpoin')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('staffcat');
Schema::dropIfExists('staff');
}
}
人员模型
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Staff extends Model
{
//
}
store method in StaffController
public function store(Request $request)
{
//
$this->validate($request,[
'st_cat_name' => 'required'
]);
$staffinfo = new Staff;
$staffinfo->catname = $request->input('st_cat_name');
$staffinfo->save();
return redirect('/staff')->with('success', 'Staff category Created');
}
这是错误消息 “ SQLSTATE [42S02]:找不到基表或视图:1146表'gchsc.staffcats'不存在(SQL:插入
staffcats
中 (catname
,updated_at
,created_at
)I want to store data in staffcat table