Support the ongoing development of Laravel.io →
Database Eloquent

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'));
Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

web-botan web-botan Joined 12 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.