如何使用laravel中的原始php从数据库中的表中获取行[关闭]

I'm trying to fetch the first row from a table using raw php in laravel. Say the table name is 'tblcompany'. I'm trying to populate my form with the data. How do I do that?

Fetching the first row from a table can be done at database level.
MySQL uses limit 1 somewhere at the bottom of the statement.
TSQL uses select top 1 at the beginning of the statement.

If you use another database language, feel free to google something like
"[Database language] equivalent of MySQL Limit"

If you really want to do it at PHP level, instead of placing
foreach($records as $record){/*Do stuff*/}, You can use
$firstRow = $records[0]

I can't give you a more detailed answer because you didn't ask a detailed question.

Please Try this:

$company = DB::select('select * from tblcompany limit 1');
Model Company
$table = 'tblcompany';

Company::first();