I have model Article, Filegroup, File.
When save new article with image, it displays this error:
{"exception":"Illuminate\Database\QueryException","message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'image' in 'field list' (SQL: insert into
articles
(title
,text
,like_count
,view_count
,comment_count
,image
,web_image
,updated_at
,created_at
) values (dsvdscdscdscsdcdsc, sacsaxasxsaxsaxsaxsaxsax, 0, 0, 0, 11, 13989, 2017-06-27 15:40:49, 2017-06-27 15:40:49))","trace":[{"file":"/var/www/laravel/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php","line":726,"function":"runQueryCallback","class":"Illuminate\Database\Connection","type":"->","args":["insert intoarticles
(title
,text
,like_count
,view_count
,comment_count
,image
,web_image
,updated_at
,created_at
) values (?, ?, ?, ?, ?, ?, ?, ?, ?)",..................
models/Article.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
protected $guarded = ['id'];
protected $with = ['image'];
public function image()
{
return $this->belongsTo('App\Models\Filegroup', 'image_id');
}
}
models/FileGroup.php
use Illuminate\Database\Eloquent\Model;
class Filegroup extends Model
{
protected $table = 'file_groups';
protected $with = ['files', 'name'];
protected $guarded = ['id'];
/**
* One-to-Many relations with SiteString.
*
* @foreignModel SiteString
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function name()
{
return $this->belongsTo('App\Models\SiteString', 'name_id');
}
/**
* Many-to-Many relations with File.
*
* @foreignModel File
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function files()
{
return $this->hasMany('App\Models\File', 'filegroup_id');
}
}
models/file.php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class File extends Model
{
protected $table = 'files';
protected $fillable = [
'mimi_type',
'path',
'width',
'height',
'size'
];
/**
* One-to-Many inverse relations with Filegroup.
*
* @foreignModel Filegroup
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function group()
{
return $this->belongsTo('App\Models\Filegroup', 'filegroup_id');
}
}
Tables articles created with migration:
class CreateArticlesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('articles', function (Blueprint $table) {
$table->increments('id');
$table->integer('image_id');
$table->text('text');
$table->string('title');
$table->integer('like_count');
$table->integer('view_count');
$table->integer('comment_count');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('articles');
}
}
image
exists in tablearticles
– ImAtWarimage
andweb_image
does not exists in your articles migration – Nerea