htantruc htantruc - 1 year ago 101
PHP Question

Show selected option from database in laravel

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)
@if($news->id_type == $type->idtype)


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

Answer Source

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

@if($news->id_type == $type->idtype)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download