문제

How would I get inside of a custom model the columns for a specific MySQL table using Eloquent in Laravel

I was trying DB::query("SHOW COLUMNS FROM " . $table) but without any success

도움이 되었습니까?

해결책

What you are using is not Eloquent, but raw database queries.

RAW queries:

$table = 'your_table';
$columns = DB::select("SHOW COLUMNS FROM ". $table);

다른 팁

There's no Eloquent function for this as it is considered out of its scope. I'd just do the following:

DB::select('show columns from '.(new MyModel)->getTable());
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top