gpt4 book ai didi

javascript - Laravel 5.4 中如果记录存在禁用按钮

转载 作者:行者123 更新时间:2023-12-01 03:38:03 24 4
gpt4 key购买 nike

如果我在用户表中注册了用户,我试图禁用按钮,但我使用的方法不会停用我想要停用的按钮,而是将其停用到所有寄存器。

这是我的用户迁移:

public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->engine = 'InnoDB';
$table->increments('id');
$table->integer('id_employee')->unsigned();
$table->string('username')->unique();//Cedula
$table->string('name')->nullable();
$table->string('password', 60)->nullable();
$table->string('email', 60)->nullable();
$table->rememberToken();
$table->timestamps();
$table->foreign('id_employee')->references('id')->on('employees')
->onUpdate('cascade')->onDelete('cascade');
});
}

这是我的用户模型:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Employee extends Model
{
protected $table = 'employees';

protected $fillable = ['doc_number', 'user_code', 'name', 'last_name', 'settlement', 'address', 'city' , 'zip_code', 'email', 'phone', 'position', 'departments_id', 'hire_date'];

protected $guarded = ['id'];

public function departments()
{
return $this->belongsTo('App\Department');
}

public function user()
{
return $this->hasOne('App\User');
}

//Query para buscador
public function scopeName($query, $name)
{
$query->leftJoin('departments','employees.departments_id','=','departments.id')
->select('employees.*','departments.id as deptID','departments.name as department')
->where('employees.name','like',"%$name%")
->orWhere('employees.last_name','like',"%$name%")
->orWhere('employees.position','like',"%$name%")
->orWhere('employees.email','like',"%$name%")
->orWhere('employees.doc_number','like',"%$name%")
->orWhere('departments.name','like',"%$name%");
}
}

这是我的索引方法 Controller :

public function index(Request $request)
{
$employees = Employee::name($request->get('criteria'))->orderBy('name','asc')->paginate(6);

$departments = Department::orderBy('id', 'desc')->pluck('name', 'id');

$users = User::orderBy('id', 'desc')->pluck('username', 'id');

return view('employees.index', compact('employees', 'departments', 'users'))
->with('i', ($request->input('page', 1) - 1) * 6);
}

这是我的带按钮的 Blade View :

<td>
<div class="btn-group">
@if(count($users) === 0)
<a href="{{ URL::route('padron.create', $employee->id) }}" type="submit" class="btn btn-success btn-sm" data-toggle="tooltip" rel="tooltip" data-placement="top" title="Confirmar votante">Confirmar</a>

@else
<a type="submit" class="btn btn-success btn-sm" data-toggle="tooltip" rel="tooltip" data-placement="top" disabled="disabled" title="Confirmar votante">Confirmar</a>

@endif
</div>
</td>

最佳答案

  1. 在 Controller 函数中成功返回语句后发送回一个值
  2. 并使用此命令检查该值是否存在于您的 View 中

关于javascript - Laravel 5.4 中如果记录存在禁用按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44104150/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com