prasanna purohit
prasanna purohit

Reputation: 98

get the selected value from the dropdown in laravel

i'm working with the laravel and html here. anyhow by doing this i got the data from controller to view and showed that in the dropdown. now the next part is to make crud operation for that. so whenever i select the option from the dropdown the particular ID element should be display. this is my view code:

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

and this is my controller:

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

When I run this I'm getting this error: syntax error, unexpected '=' (View: /home/prasanna/Billing-master/resources/views/Qtcreate.blade.php).

please help me to come over this. thank you advance

Upvotes: 0

Views: 226

Answers (2)

iAmGroot
iAmGroot

Reputation: 868

class Client extends Model
{
    protected $table = 'client';
    protected $primaryKey = 'Cid';
    protected $guarded = ['Qid'];
    protected $fillable = ['name', 'address', 'contact', 'created_at', 'updated_at' ]; 
    public function client()
    {
        return $this->hasMany('App\qt',Qid,Cid);
    }
}




class qt extends Model
{
    protected $table = 'qts';
    protected $primaryKey = 'Qid';
    protected $guarded = ['Cid'];
    protected $fillable=['Itemname','Quantity','Price','Tax','Total','GrandTotal','created_at', 'updated_at'];
    public function qts()
    {
        return $this->belongsTo('App\Client',Cid,Qid);
    }
}

Upvotes: 1

Dapo Michaels
Dapo Michaels

Reputation: 392

A Client hasMany qts & a qts belongsTo a client. Try to change those relationships first.

Upvotes: 1

Related Questions