I would like to know if there is any query in MYSQL that allows to return a value, in case that the query is affirmative, as is the query.
select usuario_ad, nombre, asignacion
from usuarios
where usuario_ad='danielad' and asignancion='paolaad';
I would like to know if there is any query in MYSQL that allows to return a value, in case that the query is affirmative, as is the query.
select usuario_ad, nombre, asignacion
from usuarios
where usuario_ad='danielad' and asignancion='paolaad';
Going back to the idea of @ A.Cedano it occurs to me that with the query Builder you do it in the following way
QUERY BUILDER CODE
$data = \DB::table('usuarios')
->selectRaw('COUNT(*) total')
->where('usuario_ad', 'danielad')
->where('asignacion', 'paolaad')
->get();
if($data > 0)
{
return 1;
}else{
return 0;
}
EXPLANATION
selectRaw()
to make the COUNT()
of the column WHERE
with the operator AND
to make it necessary for 2 conditions to be met; here we use two methods WHERE
if
we do a check, if the variable that contains the query is greater than 0 then if there is data, otherwise we return 0 CODE WITH ELOQUENT
$data = ModelName::where('usuario_ad', 'danielad')
->where('asignacion', 'paolaad')
->count()
->get();
if($data > 0){
return 1;
}else{
return 0;
}
EXPLANATION
You can if you are using a model for the table usuarios
assign it where I placed ModelName
that is replace it