0

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

4
Contributors
7
Replies
40
Views
1 Year
Discussion Span
Last Post by Sikander Nasar
0

Show your model object and your controller code.

0
    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');
        }

    }
0

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.

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.