小编N. *_*fin的帖子

我想禁用基于 auth()->user()->id 的删除按钮 (LARAVEL 8)

我已经创建了用户索引,在该表上显示除密码之外的所有用户数据,并在最后一个字段中设置了删除用户的操作。问题是我只想为当时登录的用户禁用删除按钮。但我所做的是禁用所有用户删除按钮,请帮助我如何解决这个问题。我试图找到教程,但还没有找到。下面是我的条件代码:

@if (auth()->user()->id)
    <button class="btn btn-outline-danger
    btn-xs" disabled><i class="fe fe-trash"></i>Delete</button>
@else
    <button class="btn btn-outline-danger
    btn-xs"><i class="fe fe-trash"></i>Delete</button>
@endif
Run Code Online (Sandbox Code Playgroud)

在 UserController 中显示所有用户数据我使用以下代码:

public function index(){
    $users = User::all();
    return view('admin.users.index', ['users'=> $users]);
}
Run Code Online (Sandbox Code Playgroud)

在index.blade中,我应用此代码来显示所有数据:

<table id="dataTableBasic" class="table" style="width:100%">
    <thead>
    <tr>
        <th>{{ __('Username') }}</th>
        <th>{{ __('Name') }}</th>
        <th>{{ __('Email') }}</th>
        <th>{{ __('Role') }}</th>
        <th>{{ __('Posts') }}</th>
        <th>{{ __('Action') }}</th>
    </tr>
    </thead>
    <tbody>
    @foreach($users as $user)
    <tr>
        <td><a href="{{route('user.profile.show', $user->id)}}" class="text-inherit link-primary">{{$user->username}}</a></td>
        <td>{{$user->name}}</td>
        <td><a href="mailto:{{$user->email}}" class="text-inherit link-primary">{{$user->email}}</a></td>
        <td>Administrator</td>
        <td><a href="#" class="text-inherit">100</a></td>
        <td>
            <form …
Run Code Online (Sandbox Code Playgroud)

php conditional-statements laravel

0
推荐指数
1
解决办法
1094
查看次数

标签 统计

conditional-statements ×1

laravel ×1

php ×1