Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9185539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:18:07+00:00 2026-06-17T19:18:07+00:00

I am starting to use the Laravel framework, and I have a problem with

  • 0

I am starting to use the Laravel framework, and I have a problem with the fluent query builder. In a where condition, if I am using raw values or Input::get(), it retrieves the results and executes correctly, but when I use an assigned variable it shows “Undefined variable” errors.

$properties = Listing::where(function($query)
{
    if (Input::has('property-type')) $query->where('property_type', '=',Input::get('property-type'));
})->get();

it works correctly, but if I do

$pt=Input::get('property-type');
$properties = Listing::where(function($query)
{
    if ($pt!='') $query->where('property_type', '=',$pt);
})->get();

it returns the error

Undefined variable: pt

If I print the variable “$pt” it contains the value.

I want to use only the variable values, because I should pass these value from the controller to the model as parameters, and build the query in the model function. Am I doing something wrong? Is the variable not assigned before the query execution? Please, can anyone help me to resolve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:18:09+00:00Added an answer on June 17, 2026 at 7:18 pm

    The reason you are struggling with the variable is because it’s outside of the anonymous function’s scope.

    I wouldn’t worry about passing variables to the models to construct the query, simply use the awesome Input class methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting to use Entity Framework. Let's say I have to Entity from my
I am starting to use MVC4 Web API project, I have controller with multiple
Just starting to use Ruby on Rails to see what its like. I have
I'm just starting to use Git, and I have a question: When I create
I am just starting to use RabbitMQ and AMQP in general. I have a
I'm starting to use Dojo; this is (essentially) my introduction to AJAX. We have
I´m starting to use jenkins and I have problems with the authentication when I
I'm starting to use Apache buildr. As far as I understand, I always have
I'm starting to use the Simple XML framework with annotations ( link ) for
Just starting to use backbone and have a quick question and thought I'd write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.