error with relationship

why i have this error. ( i really have no idea dd ) https://flareapp.io/share/x5MWyJwP code:
Repeater::make('purchaseBrands')
->relationship()
->schema([
Select::make('brand_id')
->label('Brand')
->relationship('brand', 'name', function (Builder $query, Get $get) {
if($get('../../supplier_id') === null) {
return;
}
$brandIds = Supplier::find($get('../../supplier_id'))->brand_id;
$query->whereIn('id', $brandIds);
})
->searchable()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->required()
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
TextInput::make('brand_amount')
->numeric()
->required()
]),
TextInput::make('amount')->required()
->required(),
])
Repeater::make('purchaseBrands')
->relationship()
->schema([
Select::make('brand_id')
->label('Brand')
->relationship('brand', 'name', function (Builder $query, Get $get) {
if($get('../../supplier_id') === null) {
return;
}
$brandIds = Supplier::find($get('../../supplier_id'))->brand_id;
$query->whereIn('id', $brandIds);
})
->searchable()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
->required()
->preload()
->createOptionForm([
TextInput::make('name')
->required()
->label('New Brand'),
TextInput::make('brand_amount')
->numeric()
->required()
]),
TextInput::make('amount')->required()
->required(),
])
problem is with relationship
Flare
Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in /var/www/html/shesyidvebi/vendor/filament/forms/src/Components/Select.php on line 764 - The error occurred at http://127.0.0.1:8000/admin/purchases/5/edit
Solution:
its my problem dd
Jump to solution
9 Replies
toeknee
toeknee10mo ago
select is returning null... but it stats it needs to be a relation. so you should return: $query instead.
gigiloouu
gigiloouuOP10mo ago
where i should return $query can u write it ?
toeknee
toeknee10mo ago
I am guessing:
->relationship('brand', 'name', function (Builder $query, Get $get) {
if($get('../../supplier_id') === null) {
return $query; // <--- HERE
}
$brandIds = Supplier::find($get('../../supplier_id'))->brand_id;
$query->whereIn('id', $brandIds);
})
->relationship('brand', 'name', function (Builder $query, Get $get) {
if($get('../../supplier_id') === null) {
return $query; // <--- HERE
}
$brandIds = Supplier::find($get('../../supplier_id'))->brand_id;
$query->whereIn('id', $brandIds);
})
gigiloouu
gigiloouuOP10mo ago
same erorr Filament\Support\Services\RelationshipJoiner::prepareQueryForNoConstraints(): Argument #1 ($relationship) must be of type Illuminate\Database\Eloquent\Relations\Relation, null given, called in /var/www/html/shesyidvebi/vendor/filament/forms/src/Components/Select.php on line 764 thanks means i have problem in models right? hm interesting
toeknee
toeknee10mo ago
Could be, remove the function off for now. And if you get th esame error you need to review your model.
gigiloouu
gigiloouuOP10mo ago
yep same error hm like when i add Repeater::make('purchaseBrands') ->relationship() <#!----------- This ->schema([ Select::make('brand_id') ->label('Brand') ->relationship('brand', 'name', function (Builder $query, Get $get) { if($get('../../supplier_id') === null) { return $query; } $brandIds = Supplier::find($get('../../supplier_id'))->brand_id; $query->whereIn('id', $brandIds); }) ->searchable() ->disableOptionsWhenSelectedInSiblingRepeaterItems() ->required() ->preload() ->createOptionForm([ TextInput::make('name') ->required() ->label('New Brand'), TextInput::make('brand_amount') ->numeric() ->required() ]), TextInput::make('amount')->required() ->required(), ]) ->columns(2) ->addActionLabel('add blog') ->collapsible(), this relationship which i mark next i have this error tats means i have error in modal purchaseBrand sright? in purchaseBrands pivot i have this code
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;

class PurchaseBrands extends Pivot
{
public function purchase(): BelongsTo
{
return $this->belongsTo(Purchase::class);
}

public function transporter(): BelongsTo
{
return $this->belongsTo(Transporter::class);
}
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Pivot;

class PurchaseBrands extends Pivot
{
public function purchase(): BelongsTo
{
return $this->belongsTo(Purchase::class);
}

public function transporter(): BelongsTo
{
return $this->belongsTo(Transporter::class);
}
}
can u help me what i should write to work ? like i follow documentation info i have purchases table and also purchases_transport table which is pivot also transporter table where i have transporter names fuck no its about brands..
Solution
gigiloouu
gigiloouu10mo ago
its my problem dd
gigiloouu
gigiloouuOP10mo ago
i forgot.. sorry wait d i made it thanks ❤️
toeknee
toeknee10mo ago
Great.
Want results from more Discord servers?
Add your server