dimanche 15 mai 2016

Error Laravel 5.2 get values from pivot

I need some help, where is my mistake in code, why my pivot data does not appear in tag

(Trying to get property of non-object (View: )

Here is my models for Agent and Classifier

Agent:

 class Agent extends Model
{
    protected $table = 'agent';
    protected $fillable = [
        'first_name',
        'last_name'
    ];

    public function classifiers()
    {
        return $this->belongsToMany('App\Classifier', 'classifier_agent'); 
    }
}

Classifier:

class Classifier extends Model
{
    protected $table = 'classifier';
    public $fillable = ['title', 'code', 'status', 'is_special'];
    //katram klasifikatoram var but One-to-many klienti
    public function client() {
        return $this->hasMany('App\Client');
    }

    public function agents() {
        return $this->belongsToMany('App\Agent', 'classifier_agent');
    }
}

AgentController:

public function edit(Request $req) {
      $agent = Agent::find($req->id)->toArray();
      $classifier = Classifier::lists('title', 'id')->toArray();

      return view('agents/edit', ['agent' => $agent, 'action' => 'update', 'classifier'=>$classifier]);
    }

And Blade:

    <div class="form-group col-sm-12"> 
      {!! Form::label('classifier', 'Reģioni') !!}
    {!! Form::select('classifier[]', $classifier, $agent->classifier->lists('id')->toArray(),['multiple', 'class' => 'form-control selectpicker']) !!}

 </div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire