从 laravel 的下拉列表中获取选定的值

我在这里使用 laravel 和 html。无论如何,通过这样做,我从控制器获取了数据以查看并在下拉列表中显示。现在下一部分是为此进行 crud 操作。所以每当我从下拉列表中选择选项时,应该显示特定的 ID 元素。这是我的视图代码:


<div class="form-row">

    <div class="form-group col-md-6">

      <label>Name</label>

      <select name="id" class="form-control">

          @foreach($clients as $client)

          <option value="{{ $client->Cid }}" {{ $selectedclients == $client->Cid ? selected="selected" : '' }}>{{ $client->name }}</option> 

      @endforeach

      </select>

    </div>

  </div>

这是我的控制器:


 $Clients = Client::all();

    $selectedClients = Client::first()->Cid;

当我运行它时,我收到此错误:语法错误,意外的“=”(视图:/home/prasanna/Billing-master/resources/views/Qtcreate.blade.php)。


请帮我解决这个问题。提前谢谢你


HUX布斯
浏览 195回答 2
2回答

慕哥6287543

客户端hasManyqts 和 qtsbelongsTo客户端。首先尝试改变这些关系。

Qyouu

class Client extends Model{&nbsp; &nbsp; protected $table = 'client';&nbsp; &nbsp; protected $primaryKey = 'Cid';&nbsp; &nbsp; protected $guarded = ['Qid'];&nbsp; &nbsp; protected $fillable = ['name', 'address', 'contact', 'created_at', 'updated_at' ];&nbsp;&nbsp; &nbsp; public function client()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return $this->hasMany('App\qt',Qid,Cid);&nbsp; &nbsp; }}class qt extends Model{&nbsp; &nbsp; protected $table = 'qts';&nbsp; &nbsp; protected $primaryKey = 'Qid';&nbsp; &nbsp; protected $guarded = ['Cid'];&nbsp; &nbsp; protected $fillable=['Itemname','Quantity','Price','Tax','Total','GrandTotal','created_at', 'updated_at'];&nbsp; &nbsp; public function qts()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; return $this->belongsTo('App\Client',Cid,Qid);&nbsp; &nbsp; }}
打开App,查看更多内容
随时随地看视频慕课网APP