1
static function getall($input) {
$where = [];
$params = [];
$sql = 'SELECT * FROM radio_city';
if (isset($input['city']) && $input['city']) {
$where[] = ' city = ?'; // Subsequent additions to $where should specify AND/OR conditional
$params[] = $input['city']; 
}
$sql .= implode(' ', $where); 
$sql .= " GROUP BY city";
return DB::select($sql, $where, $params); 
}
}

Here I am using the Laravel(MVC) framework. I am redirecting input form from controller so how should i concatenate query with that input. So is this code works or need any modification?

1

2 Answers 2

1

You may try something like this:

public static function getAll() {
     $query = DB::table('radio_city');
     if($city = Input::get('city')) {
         $query->where('city', $city);
     }
     return $query->groupBy('city')->get();
}

Read more on the documentation. Also look at the Eloquent ORM and Scope as well. You should read the documentation first, everything is given there.

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

Comments

0

The most like is http://laravel.com/docs/queries#joins because Lavarel use a wrapper for the query, it don't use ORM, if you use a framework with ORM (for example Django) or a ORM for PHP (for example Doctrine http://www.doctrine-project.org/ that it is use in Symfony) you can make query more advanced without SQL, but with Laravel you need make it with SQL maked with wrapper of Laravel.

Comments

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.