TranceCode
TranceCode
Explore posts from servers
FFilament
Created by TranceCode on 1/6/2025 in #❓┊help
How can edit the register account?
Than you guys @LeandroFerreira and @Julien B. (aka yebor974) for the tips and answer...
9 replies
FFilament
Created by TranceCode on 1/6/2025 in #❓┊help
How can edit the register account?
here is the plan relationship in User Model
public function plans(): BelongsToMany
{
return $this->belongsToMany(Plan::class)->withPivot('start_date', 'end_date', 'is_active')->withTimestamps();
}
public function plans(): BelongsToMany
{
return $this->belongsToMany(Plan::class)->withPivot('start_date', 'end_date', 'is_active')->withTimestamps();
}
9 replies
FFilament
Created by TranceCode on 1/6/2025 in #❓┊help
How can edit the register account?
any idea guys?
9 replies
FFilament
Created by TranceCode on 12/30/2024 in #❓┊help
how can disable the createAction If?
Thank you so much bro, the code it's working! Thank you :fi: 👏 👏 👏
3 replies
FFilament
Created by TranceCode on 12/18/2024 in #❓┊help
How can create and edit page using TinyEditor
I have managed to solve the problem in another way, using templates with a static design, in this case by calling blade.php templates from a select, now I only have to add the inputs to load the text and image contents. Thank you very much, although no one answered me hahahahah 😂
2 replies
FFilament
Created by TranceCode on 12/16/2024 in #❓┊help
How can integrate Socialite in Filament
Ok, I understand you, thank you very much for the information 👌
5 replies
FFilament
Created by TranceCode on 12/16/2024 in #❓┊help
How can integrate Socialite in Filament
Thank you very much friend, if I had looked there, then do you recommend using the filament ones, of those 3 which one would you recommend the most? or is there not much difference between them? Thank you so much!
5 replies
FFilament
Created by TranceCode on 12/10/2024 in #❓┊help
How can show a modal message ?
No description
5 replies
FFilament
Created by TranceCode on 12/10/2024 in #❓┊help
How can show a modal message ?
Thank you for the tip bro @LeandroFerreira, it's working now!
5 replies
FFilament
Created by TranceCode on 11/26/2024 in #❓┊help
Display Notifications for different panels
No description
5 replies
FFilament
Created by TranceCode on 11/26/2024 in #❓┊help
Display Notifications for different panels
<?php

namespace App\Models\Company;

use App\Models\Company;
use Filament\Facades\Filament;
use Filament\Models\Contracts\HasTenants;
use Filament\Notifications\DatabaseNotification;
use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;

class Notification extends DatabaseNotification implements HasTenants
{
use HasFactory, Notifiable;
// Indica que el ID no es un entero sino un UUID
public $incrementing = false;
protected $keyType = 'string';

protected $fillable = [
'customer_id',
'type',
'data',
'read_at',
'notifiable_id',
'notifiable_type'
];

protected static function booted(): void
{
self::addGlobalScope('for_logged_company', function(Builder $builder):void {
if (auth()->guard('company')->check()) {
$user = auth()->user();
$companies = $user->companies;
if($companies->count() > 0) {
$company = $companies->first();
$companyId = $company->id;
}
}
});

self::saving(function (self $company): void {
if (auth()->guard('company')->check()) {
$user = auth()->user();
//dd($user);
$companies = $user->companies;
if ($companies->count() > 0) {
$company = $companies->first();
$company->company_id = $company->id;
}
}
});

self::creating(function (self $notification) {
if($tenant = Filament::getTenant()) {
$notification->customer_id = $tenant->id;
}
});
}

public function companies(): BelongsTo
{
return $this->belongsTo(Company::class, 'company_id');
}

public function getTenants(Panel $panel): array|Collection
{
return $this->companies;
}

public function canAccessTenant(Model $tenant): bool
{
return $this->companies->contains($tenant);
}
}
<?php

namespace App\Models\Company;

use App\Models\Company;
use Filament\Facades\Filament;
use Filament\Models\Contracts\HasTenants;
use Filament\Notifications\DatabaseNotification;
use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;

class Notification extends DatabaseNotification implements HasTenants
{
use HasFactory, Notifiable;
// Indica que el ID no es un entero sino un UUID
public $incrementing = false;
protected $keyType = 'string';

protected $fillable = [
'customer_id',
'type',
'data',
'read_at',
'notifiable_id',
'notifiable_type'
];

protected static function booted(): void
{
self::addGlobalScope('for_logged_company', function(Builder $builder):void {
if (auth()->guard('company')->check()) {
$user = auth()->user();
$companies = $user->companies;
if($companies->count() > 0) {
$company = $companies->first();
$companyId = $company->id;
}
}
});

self::saving(function (self $company): void {
if (auth()->guard('company')->check()) {
$user = auth()->user();
//dd($user);
$companies = $user->companies;
if ($companies->count() > 0) {
$company = $companies->first();
$company->company_id = $company->id;
}
}
});

self::creating(function (self $notification) {
if($tenant = Filament::getTenant()) {
$notification->customer_id = $tenant->id;
}
});
}

public function companies(): BelongsTo
{
return $this->belongsTo(Company::class, 'company_id');
}

public function getTenants(Panel $panel): array|Collection
{
return $this->companies;
}

public function canAccessTenant(Model $tenant): bool
{
return $this->companies->contains($tenant);
}
}
5 replies
FFilament
Created by TranceCode on 11/24/2024 in #❓┊help
Can't export data using ExportAction with Tenant
Or what would be your recommendation for my case? Do you think it would be a good idea to work with that data in a single table and nothing else?
20 replies
FFilament
Created by TranceCode on 11/24/2024 in #❓┊help
Can't export data using ExportAction with Tenant
If it is true, perhaps the best option is to pass that data to the table, add customer_id and tenant_id to notifications and nothing more... that way I avoid extra work... which does have me a little confused working with extend of the DatabaseNotification class, to show notifications only to the corresponding tenants and customer accounts. Well, I continue to find out and try options but always maintaining the use of filament instead of third-party packages, thanks bro!
20 replies
FFilament
Created by TranceCode on 11/24/2024 in #❓┊help
Can't export data using ExportAction with Tenant
Hey bro, thank you for share! I'm not using stancl/tenancy, i'm using the filament configuration and implements HasTenants, i'm trying to use all the configuration of Filament, with which I avoid using third-party packages, in fact I have Laravel Excel installed and configured, but I find that the filament functionality for import and export is much more complete and becomes lighter when using jobs for this task.
20 replies
FFilament
Created by TranceCode on 11/26/2024 in #❓┊help
How can show jason to html?
Well, i fix my problem using this code!
TextEntry::make('data')
->label('Detalles')
->formatStateUsing(function ($state) {
// Decodificamos el JSON, data de la tabla
$data = json_decode($state, true);
if (!$data) {
return 'Formato inválido';
}
//Construimos de json al HTML
$html = '<div>';
$html .= "<h4>{$data['title']}</h4>";
$html .= "<p>{$data['body']}</p>";
if (isset($data['actions']) && is_array($data['actions'])) {
$html .= '<ul>';
foreach ($data['actions'] as $action) {
$html .= "<li><a href='{$action['url']}' target='_blank' class='text-blue-500 hover:text-blue-700 font-semibold'>{$action['label']}</a></li>";
}
$html .= '</ul>';
}
$html .= '</div>';
return $html;
})
->html()
TextEntry::make('data')
->label('Detalles')
->formatStateUsing(function ($state) {
// Decodificamos el JSON, data de la tabla
$data = json_decode($state, true);
if (!$data) {
return 'Formato inválido';
}
//Construimos de json al HTML
$html = '<div>';
$html .= "<h4>{$data['title']}</h4>";
$html .= "<p>{$data['body']}</p>";
if (isset($data['actions']) && is_array($data['actions'])) {
$html .= '<ul>';
foreach ($data['actions'] as $action) {
$html .= "<li><a href='{$action['url']}' target='_blank' class='text-blue-500 hover:text-blue-700 font-semibold'>{$action['label']}</a></li>";
}
$html .= '</ul>';
}
$html .= '</div>';
return $html;
})
->html()
3 replies
FFilament
Created by TranceCode on 11/24/2024 in #❓┊help
Can't export data using ExportAction with Tenant
Well, I will continue testing and analyzing how to solve the problem of both the export and the notifications that I had posted in another problem here, thanks.
20 replies
FFilament
Created by TranceCode on 11/24/2024 in #❓┊help
Can't export data using ExportAction with Tenant
<?php
namespace App\Models;

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Laravel\Sanctum\HasApiTokens;

class Customer extends Authenticatable implements HasTenants
{
use HasApiTokens, HasFactory, Notifiable;

protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];

public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class);
}

public function canAccessTenant(Model $tenant): bool
{
return $this->companies->contains($tenant);
}

public function getTenants(Panel $panel): array|Collection
{
return $this->companies;
}

public function rolesForSelectInCompanyPanel(): BelongsToMany
{
return $this->belongsToMany(Role::class)->where('name', '<>', 'Administrador');
}

public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}

public function permissions(): BelongsToMany
{
return $this->belongsToMany(Permission::class);
}

public function hasRole(string $role): bool
{
return $this->roles->contains('name', $role);
}

public function hasPermission(string $permission): bool
{
return $this->permissions->contains('name', $permission);
}

public function hasAnyRole(array $roles): bool
{
return $this->roles->whereIn('name', $roles)->isNotEmpty();
}
public function hasRoles(): bool
{
return $this->roles->isNotEmpty();
}
}
<?php
namespace App\Models;

use Filament\Models\Contracts\FilamentUser;
use Filament\Models\Contracts\HasTenants;
use Filament\Panel;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Collection;
use Laravel\Sanctum\HasApiTokens;

class Customer extends Authenticatable implements HasTenants
{
use HasApiTokens, HasFactory, Notifiable;

protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password',
'remember_token',
];
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];

public function companies(): BelongsToMany
{
return $this->belongsToMany(Company::class);
}

public function canAccessTenant(Model $tenant): bool
{
return $this->companies->contains($tenant);
}

public function getTenants(Panel $panel): array|Collection
{
return $this->companies;
}

public function rolesForSelectInCompanyPanel(): BelongsToMany
{
return $this->belongsToMany(Role::class)->where('name', '<>', 'Administrador');
}

public function roles(): BelongsToMany
{
return $this->belongsToMany(Role::class);
}

public function permissions(): BelongsToMany
{
return $this->belongsToMany(Permission::class);
}

public function hasRole(string $role): bool
{
return $this->roles->contains('name', $role);
}

public function hasPermission(string $permission): bool
{
return $this->permissions->contains('name', $permission);
}

public function hasAnyRole(array $roles): bool
{
return $this->roles->whereIn('name', $roles)->isNotEmpty();
}
public function hasRoles(): bool
{
return $this->roles->isNotEmpty();
}
}
20 replies
FFilament
Created by TranceCode on 11/24/2024 in #❓┊help
Can't export data using ExportAction with Tenant
Of course it is not the company, out of confusion I put company, but apart from that when I put customer_id it still says that it is missing the user_id, in short Customer is the model of the Company Panel and this extends authenticatable
20 replies
FFilament
Created by bwurtz999 on 11/26/2024 in #❓┊help
HintAction Adding to Select Element
No description
14 replies
FFilament
Created by TranceCode on 11/24/2024 in #❓┊help
Can't export data using ExportAction with Tenant
Then the problem of the exportAcion and importAcion functionalities are not configured or detailed for tenant and panels in the documentation. I hope you understand my explanation
20 replies