kokpithua
kokpithua
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
was struggling with this for like 2 hours
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
Now it worked. Thank you very much I geniunely appreciate it
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
in other scenarios where i display the tags beloning to the id everything works correctly
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
//Tag model
public function tasks()
{
return $this->belongsToMany(Task::class);
}
//Task Model
public function tags()
{
return $this->belongsToMany(Tag::class, 'task_tag', 'task_id', 'tag_id');
}
//Tag model
public function tasks()
{
return $this->belongsToMany(Task::class);
}
//Task Model
public function tags()
{
return $this->belongsToMany(Tag::class, 'task_tag', 'task_id', 'tag_id');
}
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
and each of the models uses the return $this->belongsToMany()
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
Maybe I haven't really explained it properly
Schema::create('task_tag', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('task_id');
$table->unsignedBigInteger('tag_id');

$table->foreign('task_id')->references('id')->on('tasks')->onDelete('cascade');
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
});
}
Schema::create('task_tag', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('task_id');
$table->unsignedBigInteger('tag_id');

$table->foreign('task_id')->references('id')->on('tasks')->onDelete('cascade');
$table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade');
});
}
this is the relation
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
Because if i convert it to an array i get back the tag and the id of the task it belongs to
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
its here when i try to filter
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
I dont think so because in other cases where i display the data the relation is set up properly and its still displayed
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
Ok but i think the issue stems from the fact that the filter is trying to select a value from the task table when instead it should do so from the table dedicated to their many to many relation task_tag. Where in the resource.php do i change the table from which te data is being taken from
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
so the query should look something like this
SELECT
count(*) AS aggregate
FROM
task_tag
WHERE
(tag_id IN (2))
SELECT
count(*) AS aggregate
FROM
task_tag
WHERE
(tag_id IN (2))
Any tips on how i would go on with implementing this?
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
I think i figured out the issue. The sql is searching for the column tags = 2 when it should search for the id = 2
public static function table(Table $table): Table
{

$tags = Tag::all();

$tagOptions = [];
foreach ($tags as $tag) {
$tagOptions[$tag->id] = $tag->name;
}
return $table
public static function table(Table $table): Table
{

$tags = Tag::all();

$tagOptions = [];
foreach ($tags as $tag) {
$tagOptions[$tag->id] = $tag->name;
}
return $table
Tables\Filters\SelectFilter::make('tags')
->multiple()
->options($tagOptions)
->label('Tags')
->placeholder('Filter by Tags'),
])
Tables\Filters\SelectFilter::make('tags')
->multiple()
->options($tagOptions)
->label('Tags')
->placeholder('Filter by Tags'),
])
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
Still doesn't work getting the same error
27 replies
FFilament
Created by kokpithua on 11/6/2023 in #❓┊help
Filtering many to many relations
Tables\Filters\SelectFilter::make('tags')
->relationship('task_id', 'tag_id')
->multiple()
->options($tagOptions)
->label('Tags')
->placeholder('Filter by Tags')
])
Tables\Filters\SelectFilter::make('tags')
->relationship('task_id', 'tag_id')
->multiple()
->options($tagOptions)
->label('Tags')
->placeholder('Filter by Tags')
])
27 replies
FFilament
Created by kokpithua on 11/5/2023 in #❓┊help
Abstract methods in models
Anyway its solved but for anyone having the same issue
class User extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];

public function canAccessPanel(Panel $panel): bool {
return str_ends_with($this->email, '@dev.tribes.work') && $this->user_type === 'admin';
}
}
class User extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];

public function canAccessPanel(Panel $panel): bool {
return str_ends_with($this->email, '@dev.tribes.work') && $this->user_type === 'admin';
}
}
8 replies
FFilament
Created by kokpithua on 11/5/2023 in #❓┊help
Abstract methods in models
It had to do with the function name. Apparently canAccessPanel was not the correct one
8 replies
FFilament
Created by kokpithua on 11/5/2023 in #❓┊help
Abstract methods in models
according to the debugger the error happens here
public function canAccessFilament(): bol{
return str_ends_with ($this->email , '@tribes.work.com');
}
public function canAccessFilament(): bol{
return str_ends_with ($this->email , '@tribes.work.com');
}
8 replies
FFilament
Created by kokpithua on 11/5/2023 in #❓┊help
Abstract methods in models
<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];

public function canAccessFilament(): bol{
return str_ends_with ($this->email , '@tribes.work.com');
}
}
<?php

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use Filament\Models\Contracts\FilamentUser;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable implements FilamentUser
{
use HasApiTokens, HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];

public function canAccessFilament(): bol{
return str_ends_with ($this->email , '@tribes.work.com');
}
}
8 replies