Это моя модель. Теперь я хочу, чтобы добавить новый элемент, но я получаю эту ошибку: SQLSTATE [23000]: Integrity нарушение ограничения: 1048Добавить новый товар на laravel 4 используя разные таблицы
<?php
class Items extends Eloquent
{
protected $guarded = [
'id',
];
protected $fillable = [
'name',
'description',
'price',
'brand',
];
protected $table = 'items';
public function user()
{
return $this->hasOne('User', 'user_ID', 'id');
}
public function size()
{
return DB::table('sizes')->select('size')
->where('id', $this->size_ID)->first()->size;
}
public function color()
{
return DB::table('colors')->select('color')
->where('id', $this->color_ID)->first()->color;
}
public function condition()
{
return DB::table('conditions')->select('type')
->where('id', $this->condition_ID)->first()->type;
}
public function category()
{
return DB::table('categories')->select('category')
->where('id', $this->category_ID)->first()->category;
}
public function images()
{
return DB::table('images')->select('image')
->where('item_id', $this->id)->first()->image;
}
}
И это мой пост способ сохранить элемент.
public function store()
{
$item = new Items;
$item->user_ID = Auth::id();
$item->name = Input::get('name');
$item->description = Input::get('description');
$item->price = Input::get('price');
$item->brand = Input::get('brand');
$item->category = Input::get('Category');
$item->condition = Input::get('Condition');
$item->color = Input::get('Color');
$item->save();
}
Вот фотография категории таблицы, состояния и таблицы цветов имеет ту же логику. http://imgur.com/9NCMYui
Спасибо за ваш ответ! Мое объяснение в вопросе было не очень умно. Как показано на картинке, у меня есть таблица категорий. Моя идея была такой: когда пользователь вводит категорию techonolgy на новый элемент, в таблице items category_id будет 1. То же самое для состояния и цвета! Я действительно не знаю, как это сделать, так как я новичок в laravel и php тоже. –