Support the ongoing development of Laravel.io →
posted 7 years ago
Database
Last updated 2 years ago.
0
class Test extends Model {
    private static $_prefix = '_prefix';
    public function __construct(array $attributes = array()) { 
        // parent::__construct($attributes); 
        self::$prefix = 'abc'; 
    }
    public static function custom_table(){ return self::$_prefix.'table_name'; }
}
Last updated 7 years ago.
0

Thanks ilinovster

But Constructor not work self::$prefix = 'abc'; When I call in public static function custom_table(){ return self::$_prefix.'table_name'; }

I define method setPrefix() and call self::setPrefix() // working

[php] class Test extends Model {

protected $table = 'lang_values';


// private static $_prefix = '';
/* 
public function __construct(array $attributes = array()) {
	 self::$prefix = 'abc'; 
}

*/

public static function setPrefix() {
   	$prefix = config('app._prefix');
    return $prefix[0];
}

public static function service_table(){
	return self::setPrefix().'table_name';
}

public static function getAll()
{
    echo $cont = self::service_table();
    return DB::select("select * from $cont where avail = 1");
}

}

[php]

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

nhantam nhantam Joined 29 May 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.