I need help writing a query in eloquent from three tables, where fields table, field_value and users.
Fields have id,type,name and options columns.
Field value have id,user_id,field_id,text
And take form users - id.
So, i want to display all fields as inputs. If this field with user_id have row in field_value table that input have text value.
Please, help me create model,controller and blade MY models
// Field model
public function fvalue(){
return $this->hasMany('Fvalues');
}
// User model
public function fvalues(){
return $this->hasOne('Fvalues');
}
// Field value model
public function field(){
return $this->belongsTo('Field');
}
// Controller
public function getEdit(){
$user_id = Auth::user()->id;
$user = User::find($user_id);
$fields = Field::allt();
$fvalue = $user->fvalue;
return View::make('site.profile',compact('user','fvalue','fields'));
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community