Get enum options values in laravel eloquent

Get enum options values in laravel eloquent

In this post, i will tell you how to get enum values of a column in a table using Laravel.

Unfortunately, Laravel does not have short method to get enum values so i use here laravel query builder to get enum values manually by writing our own custom methods.

First, define a static method within a model class so that you can easily access anywhere within application by model class name.

I suggest you to create a helper class and put this method within helper class.

Click here to know : how to create helper class in Laravel

I have created a General helper class with the help of above link and paste this method into General class.

  1. <?php
  2. class General {
  3. public static function getEnumValues($table, $column) {
  4. $type = DB::select(DB::raw("SHOW COLUMNS FROM $table WHERE Field = '{$column}'"))[0]->Type ;
  5. preg_match('/^enum\((.*)\)$/', $type, $matches);
  6. $enum = array();
  7. foreach( explode(',', $matches[1]) as $value )
  8. {
  9. $v = trim( $value, "'" );
  10. $enum = array_add($enum, $v, $v);
  11. }
  12. return $enum;
  13. }
  14. }

Now i can get enum values of a table by calling getEnumValues method.

    $enumoption = General::getEnumValues('table_name','column_name') ;

Phone: (+91) 8800417876
Noida, 201301
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
porno izle
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat
sohbet okey oyna
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort