Azhar Nabil Azhar Nabil - 1 year ago 136
PHP Question

laravel 5.2 how to put the old value in Form::select during edit table with it's relation

I developed a website for matches.I have table for leagues and table for statistics .table league has relation one to many with statistics table.

In page statistics I have Form::select

This is the code

<div class="form-group">
<label for="name" class="col-md-3 control-label"><br> هذه الاحصائيه</label>
<div class="col-md-9">
{{ Form::select("toLeague", $leagues, null, ['class' => 'form-control']) }}


****User will select league for statistic,when I edit the statistic I want the old value of the league in Form::select****

How to do this in form select?
please any one help me

Answer Source

You can use Form-model binding to accomplish that.

Form::model($statistic, ['route' => ['.......']])

It'll auto select your stored values matching field name with form input name.

Here you will get some idea.

Also there is another way. Consider your foreign key name is leage_id in statistics table update your form like below:

{{ Form::select("toLeague", $leagues, $statistic->league_id, ['class' => 'form-control']) }}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download