我不是很擅長ajax。我想取消選中“活動”用戶的復選框。
- 我的 LoginController 中有這個
public function login()
{
$credentials = $this->validate(request(), [
'email' => 'email|required|string',
'password' => 'required|string',
]);
if (Auth::attempt($credentials)) { //auth attemptdevuelve verdadero o falso en caso de que las credenciales correspondan o no
//Inician cambios RDAN
$user = Auth::user();
if($user->active) // checking your user is active or not
{
if ($user->hasRole('admin')) {
return redirect('main');
} else if ($user->hasRole('externo')) {
return redirect('es/user_form');
} else if ($user->hasRole('profesor')) {
return redirect('main');
} else if ($user->hasRole('registrador')) {
return redirect('select_lang');
} else {
return back()->withErrors(['email' => 'Incorrect user permissions'])
->withInput(request(['email']));
}
}
else
{
Auth::logout(); //to logout user
return back()->withErrors(['email' => 'Account Deactivated please contact admin'])->withInput(request(['email'])); // error message if user deactivated.
}
//Terminan cambios RDAN
} else {
return back()->withErrors(['email' => 'Incorrect user permissions'])
->withInput(request(['email']));
}
}
- 索引視圖:
@foreach($users ?? '' as $user)
<tr>
<td class="small text-center">{{$user->name}}</td>
<td class="small text-center">{{$user->email}}</td>
<td class="small text-center">
@foreach($user->roles as $role)
{{$role->nombre_rol. '-'. ' '}}
@endforeach
</td>
<td class="small text-center">
<input {{$user->active=='1'?'checked':''}} type="checkbox" name="active" value="1">
</td>
<td class="small text-center">
<div class="row">
<div >
<!--VIEW-->
<button onclick="verUsuario({{$user->id}})" hljs-number">1">
<i hljs-string">"></i>
</button>
</div>
<div >
<!--EDIT-->
<button onclick="editarUsuario({{$user->id}})" hljs-number">1">
<i hljs-string">"></i>
</button>
</div>
<!--Delete-->
<form id="delete" action="{{url('Usuario/'.$user->id)}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<button type="submit" onclick="return confirm('Va a borrar la usuario {{$user->name}} ?está seguro?')" hljs-number">1"><i hljs-string">"></i></button>
</form>
</div>
</td>
</tr>
@endforeach
在 MySQL 資料庫中,我在“users”表中添加了“tinyint(1)”型別的“活動”列。我將它添加到用戶“管理員”可以使用復選框啟用或禁用用戶的視圖中。我不明白如何確保如果未檢查 0 的值更改。復選框不在表單中,它在我的索引中作為一列。有人能幫我嗎?
uj5u.com熱心網友回復:
我想你忘記了條件中的圓括號
<input {{((int)$user->active==1)?'checked':''}} type="checkbox" name="active" value="1">
如果不是這就是您要查找的內容,并且 active 屬性始終為 false,那么您可能忘記在模型 User 中添加 active 屬性
uj5u.com熱心網友回復:
<element id="blabla" onclick="uncheck()" />
JS:
getElementById(blabla)
blabla.checked = true/false
PHP:
DB::table('tablename')->update(['checkbox' => 0/1]);
此外,如果您使用布林值而不是整數會更好,因為它是您需要的真實型別,而且它更簡單、更符合邏輯并且可能更安全
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/407376.html
標籤:
