Drivers table:
public function up(){ Schema::create('drivers', function (Blueprint $table) { $table->collation = 'utf8_general_ci'; $table->charset = 'utf8'; $table->increments('id'); $table->integer('car_id')->unsigned()->nullable(); $table->foreign('car_id')->references('id')->on('cars'); $table->string('name',20); $table->string('surname',20); $table->string('father',20); $table->string('phone',13)->unique(); $table->integer('expirience'); $table->text('description'); $table->integer('number')->unsigned()->default(0); $table->boolean('has_car'); $table->boolean('is_worker'); $table->boolean('is_new'); $table->engine = 'InnoDB'; }); Driver model
<?php namespace App\Models; use App\Models\Car; use App\Models\Mod; use App\Models\Color; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Lang; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Validator; class Driver extends Model { protected $table = 'drivers'; public $timestamps = false; protected $fillable = [ 'id', 'name', 'surname', 'father', 'phone', 'expirience', 'number', 'has_car', 'is_worker', 'is_new', 'car_id', ]; public function car() { return $this->belongsTo(Car::class); } } Machine table:
public function up(){ Schema::create('cars', function (Blueprint $table) { $table->collation = 'utf8_general_ci'; $table->charset = 'utf8'; $table->increments('id'); $table->string('number',15)->unique(); $table->enum('body', ['sedan', 'hatchback', 'universal', 'minivan', 'microbus',]); $table->boolean('climat'); $table->string('color',25)->nullable(); $table->foreign('color')->references('title')->on('colors'); $table->integer('model_id')->unsigned()->nullable(); $table->foreign('model_id')->references('id')->on('models'); $table->engine = 'InnoDB'; }); } Machine model:
namespace App\Models; use Illuminate\Support\Facades\DB; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Validator; class Car extends Model { protected $table = 'cars'; public $timestamps = false; protected $fillable = [ 'id', 'color', 'number', 'body', 'climat', 'model_id', ]; public function driver() { return $this->hasOne(Driver::class); } } When you call $ driver-> car - it works, when you call $ car-> driver - "Undefined" property: stdClass :: $ driver ". What's the problem? Tell me, please.