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 '' inconnu dans where clause (SQL: select * from companyprofiles where = 2 limit 1)
what i have is user_id thus what i need to choose

Recommended Answers

All 7 Replies

Member Avatar

Show your model object and your controller code.

    `   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

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

Please try to do in this way.

Be a part of the DaniWeb community

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