Open ahoiroman opened 4 years ago
I checked out the line in the trace:
if (!$attributes instanceof Model) {
$entity = $relation->getRelated()
->where($attributes)->firstOrFail();
}
In this case !$attributes instanceof Model
returns false
and this is the reason why it fails.
Can you post the full example (at least the model classes and the db-migrations)? Also, what version on Laravel are you using?
Hi.
thanks for your response. If you need something more, please let me know.
PositionProduct.php
<?php
namespace App;
use App\Traits\ProductTrait;
use LaravelFillableRelations\Eloquent\Concerns\HasFillableRelations;
/**
* Class PositionProduct
*
* @package App
*/
class PositionProduct extends Product
{
use ProductTrait, HasFillableRelations;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable
= [
'title',
'description',
'price',
'setup',
'vat',
'recurring',
'contractperiods',
'accountingperiods',
'custom',
];
protected $fillable_relations = ['category'];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts
= [
'contractperiods' => 'object',
'accountingperiods' => 'object',
'vat' => 'integer',
'price' => 'float',
'setup' => 'float',
'recurring' => 'boolean',
'custom' => 'boolean',
'description' => 'string',
];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function category()
{
return $this->belongsTo(PositionProductCategory::class);
}
}
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePositionProductsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('position_products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->boolean('custom');
$table->bigInteger('category_id')->nullable();
$table->string('title');
$table->longText('description')->nullable();
$table->float('price');
$table->float('setup');
$table->float('vat');
$table->boolean('recurring');
$table->json('accountingperiods')->nullable();
$table->json('contractperiods')->nullable();
$table->string('slug', 150)->nullable();
$table->softDeletes();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('position_products');
}
}
Hello everybody,
I am trying to implement this package. Unfortunately I am getting this error:
once I am running
This is the trace:
This is the relation in the model:
And of course
PositionProductCategory
does exist.Maybe the problem is, that my model do not extend
Model
butProduct
andProductCategory
?