Laravel alias for table name using Eloquent

When we have a very long name like table names, it is difficult to call it. For example, look at the code below.

$users = DB::table('really_long_table_name')

           ->select('really_long_table_name.id')

           ->get();

In such cases, we can use aliases. Laravel supports the use of aliases.

The above code becomes this:

$users = DB::table('really_long_table_name AS t')

           ->select('t.id AS uid')

           ->get();

While using an alias and trying to soft delete, it might cause an error. To make alias work with soft delete. Use ->withTrashed() and ->whereNull('table_alias.deleted_at').