Azhar Nabil Azhar Nabil - 1 month ago 5
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']) }}


</div>
</div>


****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

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.

https://laravelcollective.com/docs/5.3/html#form-model-binding

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']) }}
Comments