Q:

Laravel Relationship Not Working

I am attempting to setup a relationship between two Eloquent models User and Company. User is the standard model that comes standard with a new Laravel project and Company is a model that was created using Artisan.
I have setup the relationship in the following way:
User class:
<?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'];

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

    public function companies() {
        return $this->hasMany('App\Company');
    }
}

Company Class:
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\User;

class Company extends Model
{

    protected $table = 'companies';

    public function owning_user() {
        return $this->belongsTo('App\User', 'id');
    }

}

I am attempting to create the models using the following code in the DatabaseSeeder class (it also does this in tinker):
$user = new \App\User();
$user->name = "Josh Pennington";
$user->email = 'xxx@xxx.xxx';
$user->password = bcrypt('xxx');
$user->save();

$company = new \App\Company();
$company->name = "Business Name";
$company->default_tax_rate = 6.5;
$company->owning_user = $user;
$company->save();

However, I get the following error:
[Illuminate\Database\QueryException]                                                                                                                 
  SQLSTATE[42S22]: Column not found: 1054 Unknown column 'owning_user' in 'field list' (SQL: insert into `companies` (`name`, `default_tax_rate`, `ow  
  ning_user`, `updated_at`, `created_at`) values (Business Name, 6.5, {"name":"Josh Pennington","email":"xxx@xxx.xxx","updated_at":"2015-07-06 23:09:  
  11","created_at":"2015-07-06 23:09:11","id":1}, 2015-07-06 23:09:11, 2015-07-06 23:09:11)) 

As you can see, it thinks that owning_user is the column name, when it should actually be user_id as the column name and it should not be giving the JSON version of the object in the query. What blatantly obvious mistake have I made?

A:

You can do this and supply the foreign key to "user_id" property of the company class:
$company = new \App\Company();
$company->name = "Business Name";
$company->default_tax_rate = 6.5;
$company->user_id = $user->id;
$company->save();

OR you can use the eloquent owning_user method of the company class, passing to it a User instance.
$company = new \App\Company();
$company->name = "Business Name";
$company->default_tax_rate = 6.5;
$company->owning_user()->associate($user);
$company->save();

