Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Namespace in query

Hi guys. Is there anyway to register namespaces to prevent having to use full namespace in a query on a model?

$api_method = Apiv2Method::query()
            ->join("Core\Models\Apiv2AuthType", " = Core\Models\Apiv2Method.auth_type_id" , "a")
            ->where("Core\Models\Apiv2Method.method_name = :method_name:")
            ->andWhere("Core\Models\ = true AND = true")
            ->bind(["method_name" => $this->methodName])

Maybe look at using the ModelsManager and the addFrom() method instead? You can set an alias in there. You'll still have to reference the namespace once, but thereafter can just reference the alias.

edited Jun '20

Are you running v3.4 or v4? v3.4 has registerNamespaceAlias():, but that was removed in v4 and I'm not sure if that functionality was replaced anywhere.