my update is choosing a different column which i don't have in my table. Please i need assistance
SQLSTATE[42S22]: Column not found: 1054 Champ 'companyprofiles.id' inconnu dans where clause (SQL: select * from companyprofiles where companyprofiles.id = 2 limit 1)
what i have is user_id thus what i need to choose

Member Avatar for diafol

Show your model object and your controller code.

    controller
    `   public function update(companyprofile $companyprofile, $userid)
        {

            $profile = companyprofile::where($userid)-get();
            $profile ->fill(\Input::all());
            //return $profile;
            profile ->save();
            Session::flash('message', 'Profile Updated Successfully!');
            return Redirect::to('companyprofile');
        }`

        profile model
        <?php namespace App;

    use Illuminate\Database\Eloquent\Model;

    class companyprofile extends Model {

        protected $table = 'companyprofiles';
        public $key = 'user_id';

    protected $fillable = array('fname', 'lname','remember_token','phone','address','company_name','region','employee_no','industry','website','logo','company_code','company_name','user_id');
         public function users()
        {
            return $this->belongsTo('App\User');
        }

    }

    user model
    <?php namespace App;

    use Illuminate\Auth\Authenticatable;
    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Auth\Passwords\CanResetPassword;
    use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
    use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

    class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

        use Authenticatable, CanResetPassword;

        /**
         * The database table used by the model.
         *
         * @var string
         */

        protected $table = 'users';

        /**
         * The attributes that are mass assignable.
         *
         * @var array
         */
        protected $fillable = ['name', 'email', 'password','user_type'];

        /**
         * The attributes excluded from the model's JSON form.
         *
         * @var array
         */
        protected $hidden = ['password', 'remember_token'];

        public function Companyprofile()
        {
            return $this->hasOne('App\companyprofile');
        }

    }

Any help for me please

i have changed it but still. is there a way i can change the colum laravel is using. Say use this column user_id for the query to update instead of id. my user table has id but ny profiles table does not.

Now i do this
-$profile = companyprofile::where('user_id',$userid)->first();
but when i call the save() function i get this
-Call to a member function save() on a non-object

Hello,
Your first line of code does't make sense.
$profile = companyprofile::where($userid)-get();
There are two way to do this.
First:
$profile = companyprofile::find($userid);
Second :
$profile = companyprofile::where('user_id',$userid)->first();

Please try to do in this way.
Regards
MSN

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.