Show selected option from database in laravel

htantruc

I am a newbie in laravel. In my database, I have two tables, News(id, id_type) and Type(idtype,name). And in post News page, I use dropdown to select Type for my new news. So, when I want to show the type name of this News, I do:

<div class="controls">
            <select multiple name="Type">
            @foreach($type as $type)
                <option 
                     @if($news->id_type == $type->idtype)
                        selected="selected"
                    @endif 
                value="{{$type->idtype}}">{{$type->name}}</option>
            @endforeach

            </select>
          </div>

But I have wrong result for all type in Type tables. Help me,please and thanks for your help!!

WEBjuju

The single equals is for assignment while two equals is for comparison. Change this line to be

@if($news->id_type == $type->idtype)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Setting selected option in laravel from database

Show image from selected option

How to show selected value from database in dropdown using Laravel?

only show values from selected option

Jquery show div from option already "selected"

How to get Value from Selected Option in Laravel from 2 different table in database

as an option is selected from the select menu populated data to next select menu from database.How to show "No data availabe" when no data found

Displaying selected option from database in a select option tag

How to remove selected option from the option list in select2 multiselect and show selected options in the order they are selected

Show selected option with JS

Return table from mySQL with a selected option from the database value

Hide and show DIV's from different columns depending on selected option

JQuery - Hide/show option from previous selected dropdown

Getting selected checkbox from database - laravel

Inserting data from <option> to Database in Laravel 5.8

Laravel update database with value from option

Show html select field selected as per database laravel

Laravel Pluck Selected option

Update MySQL Database based on option selected from an HTML dropdown menu

Populate Selected option in options_for_select with boolean value from database

Codeigniter - How to Set Value Of Selected Option That Populated Data From Database

How to display data in textbox from database MySQL based on selected option?

PHP set selected option that I submitted in post from database

Update select options based on other selected option from database

show selected option in dropdown javascript

show checked when the option is selected

Show a bootstrap modal if option is selected

Reactjs show selected option by object

Show div on option selected is not working