Thursday, 15 April 2021

MYSQL alias(as) use in eloquent, filed()

 alias  is as

from table as a

https://stackoverflow.com/questions/17713730/how-to-alias-a-table-in-laravel-eloquent-queries-or-using-query-builder

To use in Eloquent. Add on top of your model

protected $table = 'table_name as alias'

//table_name should be exact as in your database

..then use in your query like

ModelName::query()->select(alias.id, alias.name)



field()


https://www.w3schools.com/sql/func_mysql_field.asp#:~:text=The%20FIELD()%20function%20returns,this%20function%20will%20return%200.

Syntax

FIELD(valueval1val2val3, ...)

Example

Return the index position of "c" in the string list:

SELECT FIELD("c""a""b");


Parameter Values

ParameterDescription
valueRequired. The value to search for in the list
val1val2val3, ....Required. The list of values to search

No comments:

Post a Comment