Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Laravel 4 - Eloquent column alias

Posted on 2014-02-04
3
Medium Priority
?
3,754 Views
Last Modified: 2014-02-10
I have a web application that is expecting a column name of “sales_order_number” however the actual column name is uppercase “SALES_ORDER_NUMBER”.  I will not be able to change the database so if I can’t do some kind of aliasing I will need to rewrite my webapp to use the new names which will be a pain. Any help would be appreciated.
0
Comment
Question by:HelpDeskGeiger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39832651
PHP has the strtoupper() function that can help.  But I don't know how to add a hook or aliasing process to Laravel's SQL queries.

Changing the application might not be as hard as you think.  In most text editors there is a find-in-files function.  You might make a case-sensitive search for sales_order_number to see how many instances of that are in your code.  If the search results look promising, the change might be the fastest way to a solution.

This is often a problem for people moving from Windows to Linux platforms. The rules about case-sensitivity are different.
http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html
0
 

Accepted Solution

by:
HelpDeskGeiger earned 0 total points
ID: 39835676
The solution was to setup mutators in the model. even though the column name was in snake case I still had to use camel case for the function name. so SALES_ORDER_NUMBER became SalesOrderNumber. here is an example:

protected function getSalesOrderNumberAttribute($value) { return $this->attributes['SALES_ORDER_NUMBER']; }
protected function setSalesOrderNumberAttribute($value) { $this->attributes['SALES_ORDER_NUMBER'] = (is_null($value) ? '' : $value); }

Open in new window

0
 

Author Closing Comment

by:HelpDeskGeiger
ID: 39846808
I found the answer in the laravel documentation.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question