@Lion97icvc

Почему шаблон Blade выдает ошибку Undefined variable $decryptedPassword?

Добрый день. Пытаюсь разобраться с таким инструментом как Filament, он использует Laravel, шаблоны Blade и livewire. Мне необходимо реализовать задачу: по клику на кнопку отобразить колонку в таблице в которой будет содержаться дешифрованный пароль. Написала код, но на этапе загрузки шаблона, мне выходит ошибка Undefined variable $decryptedPassword. Вроде бы все передаю верно, не могу понять в чем ошибка(. Вот код:
Создание таблицы:
<?php

namespace App\Filament\Resources;
use App\Filament\Resources\AccessResource\Pages;
use App\Filament\Resources\AccessResource\RelationManagers;
use App\Models\Access;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\Facades\DB;
use Filament\Tables\Columns\TextColumn;
class AccessResource extends Resource
{
    protected static ?string $model = Access::class;
    protected static ?string $pluralModelLabel = 'Пароли';
    protected static ?string $modelLabel = 'Пароли';
    protected static ?string $navigationGroup = 'Администраторам';
    public $options;
    protected static ?string $navigationIcon = 'heroicon-o-shield-exclamation';
    
    public static function table(Table $table): Table
    {
        return $table
            ->columns([
                Tables\Columns\TextColumn::make('login')
                ->label('Логин'),
                Tables\Columns\TextColumn::make('passwd')
                ->label('Зашифрованные данные')
                ->getStateUsing(function (Access $record) {
                    return view('livewire.decrypt-password', ['accessId' => $record->id]);
                }),
            ])
            ->filters([
                //
            ])
            ->actions([
                Tables\Actions\EditAction::make(),
                Tables\Actions\DeleteAction::make(),
            ])
            ->bulkActions([
                Tables\Actions\BulkActionGroup::make([
                    Tables\Actions\DeleteBulkAction::make(),
                ]),
            ]);
    }

    public static function getRelations(): array
    {
        return [
            //
        ];
    }

    public static function getPages(): array
    {
        return [
            'index' => Pages\ListAccesses::route('/'),
            'create' => Pages\CreateAccess::route('/create'),
            'edit' => Pages\EditAccess::route('/{record}/index'),
        ];
    }
}


Далее код шаблона:
<head>
    @livewireStyles
</head>
<body>
    <div>
        @if($decryptedPassword)
            <span>{{ $decryptedPassword }}</span>
        @else
            <button wire:click="decrypt">Дешифровать пароль</button>
        @endif
        @livewireScripts
    </div>
</body>


И сам компонент livewire
<?php

namespace App\Livewire;
use Livewire\Component;
class DecryptPassword extends Component
{
    public $accessId;
    public $decryptedPassword;
    public function mount($accessId)
    {
        $this->accessId = $accessId;
    }
    public function decrypt()
    {
        // Получаем ключ шифрования из переменной окружения
       ....
        // Дешифруем пароль
        .....
        ]);

        $this->decryptedPassword = $decryptedData->passwd;
    }

    public function render() :View
    {
        return view('livewire.decrypt-password', ['decryptedPassword' => $this->decryptedPassword]);
    }
}


Подскажите, что я не так делаю
  • Вопрос задан
  • 54 просмотра
Решения вопроса 1
ThunderCat
@ThunderCat
{PHP, MySql, HTML, JS, CSS} developer
-@if($decryptedPassword)
+@isset($decryptedPassword)
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы