vendredi 2 juin 2017

Laravel select box to show the name and save an id of this name

I have a problem. I want to create a '' box with the name's from a table in my database andstore just an id from that name in other table (that id is a foreign key). I will show you my code

//acao model
public function estado() {
    return $this->belongsTo('App\Estado');
}
//estado model<p>
public function acao()
{
    return $this->hasMany('App\Acao');
}

AcaoController@Create:

public function create()
{
  $estado = Estado::pluck('nome', 'id');
  return view('Backoffice.acoes.criar_acao', compact('estado'));
}

AcaoController@Store:

$data = Acao::create([
      'estado_id' => $data[estado_id],
    ]);
    return redirect()->back();
}

This way the store doesn´t work and i think that this code doesn´t work with the relationship beetween acao and estado.

Can anyone help me please Thanks



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rzvgeH
via IFTTT

Aucun commentaire:

Enregistrer un commentaire