I have created a model with migration file by artisan co mmand php artisan make:model Staff -m Created two table in migration file
Schema::create('staffcat', function (Blueprint $table) {
});
Schema::create('staff', function (Blueprint $table) {
});
Now trying to store data to staffcat table from StaffController by store method. But it's not finding staffcat table :(
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');
}
}
Staff Model
<?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');
}
Here is the error message "SQLSTATE[42S02]: Base table or view not found: 1146 Table 'gchsc.staffcats' doesn't exist (SQL: insert into
staffcats(catname,updated_at,created_at)I want to store data in staffcat table
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire