Hi,
I got 3 models : Configurator, Motor and MotorSize.
Motor can be added to Configurator using BelongsTo.
MotorSize can be added to Motor using BelongsTo.
The relations above works nice (i have added some tables below).
The problem is:
I need to get all motors that have a MotorSize property/column named "mounting" with a value of "B14"
(not sure if the terminology is correct)
I have tried different things, but nothing works.
This is my latest attempt:
$motor = Motor::query()
->whereHas('motor_size_id', function (Builder $query) {
$query->where('mounting', 'like', '%B14');
})->first();
I receive this error:
Call to undefined method App\Motor::motor_size_id()
Maybe these tables will help to understand what i'm trying to do :)
Schema::create('configurators', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('motor_id');
$table->string('gear_id');
$table->timestamps();
});
Schema::create('motors', function (Blueprint $table) {
$table->increments('id');
...... bla bla
$table->string('motor_size_id');
..... bla bla
$table->timestamps();
});
Schema::create('motor_sizes', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name')->unique();
$table->string('framesize'); // E.g. 80
$table->string('mounting'); // E.g. B14
$table->timestamps();
});