I'm getting this error while up entering data to my table
class EntryController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function entry(Request $request){
$category = category::create(['cat_name' => $request->input('cat_name')]);
$product= product::create([
'Product_name'=>$request->input('Product_name'),
'Produc_quantity'=>$request->input('Produc_quantity'),
'Product_Desc' =>$request->input('Product_Desc'),
'cat_id'=>$category->cat_id]);
class category extends Model
{
protected $fillable = array('cat_description','cat_name');
public function product()
{
return $this->hasMany(product::class);
}
//
}
these are my models
class product extends Model
{
protected $fillable = array('Product_name','Product_Desc',
'Produc_quantity','sale_price',
'cost_price');
public function category()
{
return $this->belongsTo(category::class);
}
//
}
I've removed the cat_id from $fillables in product model and this is giving this error and I'm not understanding this I've check many forums and questions but I didn't find an answer this is product table
Schema::create('products', function (Blueprint $table) {
$table->increments('product_id');
$table->string('Product_name');
$table->string('Product_Desc');
$table->integer('sale_price');
$table->integer('cost_price');
$table->integer('Produc_quantity');
$table->integer('cat_id')->unsigned();
$table->foreign('cat_id')->references('cat_id')->on('categories');
$table->timestamps();
this is category table
Schema::create('categories', function (Blueprint $table) {
$table->increments('cat_id');
$table->string('cat_name');
$table->string('cat_description');
$table->timestamps();
}
before you start your second class – RiggsFollycat_id
an auto-increment field in your database? – olibiaz