0

in Laravel i can get value of two column in one table in this code

$customerName = Customer::where('id', '=', Input::get('customerID'))->first()->customer_name;
        $created_at = Customer::where('id', '=', Input::get('customerID'))->first()->created_at;

i want to know that how to get this two value (customer_name and created_at) in one query

2 Answers 2

1

I found this way in the doc:

Customer::where('id', '=', Input::get('customerID'))->lists('customer_name', 'created_at');

http://laravel.com/docs/4.2/queries#selects

Sign up to request clarification or add additional context in comments.

Comments

1

I use this code but not sure is it optimize or not

$customerID = Input::get('customerID');
$customer = Customer::findOrFail($customerID);
$customerName = $customer->customer_name;
$created_at = $customer->created_at;

1 Comment

This works fine and will only run one query. Not much to optimize here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.