i used polimorphic relation in laravel but my problem is, how to pass relation_type dynamically (Example:When i want to create tickets for Organization pass Organization Model namespace or for Contact pass Contact Model namespace).
This is my model
class Ticket
public function relation(){
return $this->morphTo();
}
class Organization
public function tickets(){
return $this->morphMany('Ticket','relation');
}
class Contact
public function tickets(){
return $this->morphMany('Ticket','relation');
}
i don't now it is possible but i want a function that accept two param
public function ticketRelation($model, $Id){
$modelNamespace = $model::findById($id);
$ticket = new Ticket();
$ticket->save();
$modelNamespace->tickets()->save($ticket);
}
In this casse a $model param should be accept Organization or Contact to associate new ticket And if i realize this i need only one route that accept a model and an Id to associate new ticket.How to pass an class like a param in this method ?