1

I am creating a backend interface for a site made in Joomla. I am using Laravel to create the backend. Joomla has table prefixes and tend to have long table names there are some of which around 25 characters.

My issue is, I have looked around to see if that you can alias table names (so I don't have to type the table name all the time in the join statement) by I don't seem to be able to find a method for this in the query object.

ModelName::getTable(); // Happens to be a static method.

Any helper much appreciated.

Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
Bradley Weston
  • 425
  • 1
  • 7
  • 17

1 Answers1

5

As answered in that StackOverflow question:

How to alias a table in Laravel Eloquent queries (or using Query Builder)?

you can either use aliases while building your query

$users = DB::table('really_long_table_name AS t')
       ->select('t.id AS uid')
       ->get();

or define the alias in your Eloquent model

protected $table = 'really_long_table_name AS short_name';
Community
  • 1
  • 1
Gadoma
  • 6,475
  • 1
  • 31
  • 34