last day (15 days later) » 

8:37 AM
0
A: Laravel extend or use Traits dynamically

madalin ivascuuse that model value to call the function $player = Player::get(); echo Player::getName($player->id,'PlayerInfoC'); in the Player model you simply call public static function getName($id,$class) return $class::where('player_id',$id)->getName();//each class will have the function } ps: y...

 
Hi Thank you for your answer, I've updated my question.
 
does my code work?
 
I can add dynamic relation?
 
what kind of dynamic relation are you talking about?
 
I mean I can set relation during run time?
 
8:37 AM
why do you need it a run time?
 
Hi Can you chat?
 
ya, why not
 
I will explain now, what I need to achieve.

Lets say I have a Admin Panel Where I create Player with Config like:
DB connection

And I select Driver, (Driver is a Model that will be used to represent Player info like name surname and other

Each Driver has it is own column names (Like in Driver A name is presented as name_a)
So When user visit the web site

he can Se Player 1, Player 2, Player 3
When he clicks on Player 1 or 2
I want to show user info
But because the columns are different, I want to use predifend driver to get all of this info
This driver should be booted on run time
 
so you want all your players in a model? yes?
 
so
table struture

players_table (Player model) in this table I will config for databae connection to my Driver and a selected Driver
 
8:43 AM
your players are scattered on 3 dbs so you want a model to get the players no matter the db they are in
 
During runtime whe user visit player 1, i need to check wich driver to user based on player_table
Connect to that DB and show user info
Yes some kind of
And I need some kind of colum map
like if I call ->getName() is should return name
Based on driver
 
so you have in a db a players_table with the id of the player and the db it belongs to ,yes?
 
like name_g name_full depends on the driver
yes
 
ok
i undersant
 
What I thougt of
 
8:46 AM
so you want to get all the player with all the names?
 
is when i create player with all DB configs
 
or you want a single players name?
 
I will asing a driver
And on Player __construct
asign a model to use
protected function setModel(){
$this->model = $this->column_model_name
}
where this-> model will become for PlayInfoA
return $this->model->getName();
 
you will need to instanciate the model $this->model =new $this->column_model_name;
right now $this->model is a string
not the PlayInfoA class
 
8:55 AM
in your implementation how will you get the name of a player with from PlayInfoA with the id of 1?
 
Basically on PlayInfoA is a database with many tables
so my Player is just a wrapper to connect to PlayInfoA database
when the new connectin will be set

I can use PlayInfoA clase to access differet tables
It is complicated because I can't explain what I need I have it my head
but can't really explain
Maybe should I explain a real example
 

last day (15 days later) »