When i try to save a new object, i get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'epigrafe' in 'field list' (SQL: insert into articulo
(titulo
, epigrafe
, revista
, updated_at
, created_at
) values (Nuevo, 1, 1, 2016-04-11 08:23:32, 2016-04-11 08:23:32))
The insert should be on epigrafe_id (also revista_id).
Model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Articulo extends Model
{
/**
* Model table
*
*/
public $table = "articulo";
protected $fillable = [
'titulo',
];
public function revista()
{
return $this->belongsTo('App\Revista');
}
public function autores()
{
return $this->belongsToMany('App\Autor');
}
public function epigrafe()
{
return $this->belongsTo('App\Epigrafe');
}
}
Controller:
public function store(Request $request)
{
$this->validate($request, [
'titulo' => 'required|max:100',
'revista' => 'required',
'epigrafe' => 'required',
]);
$data = $request->all();
$articulo = new Articulo;
$articulo->titulo = $request->titulo;
$articulo->epigrafe = $request->epigrafe;
$articulo->revista = $request->revista;
$articulo->save();
$articulo->autores()->articulos()->attach($articulo->id);
$articulo->autores()->attach($request->autor);
Session::flash('message', 'Articulo creado satisfactoriamente!');
return redirect()->to('articulo');
}