2014-02-06 6 views
1

Я ищу в сети, но я не смог найти решение моей проблемы, Я являюсь разработчиком Codeigniter и теперь я начал проект в LaravelКак написать этот запрос в Laravel 4?

мой запрос в CodeIgniter Активная запись так:

public function show_brt($id = 0,$tax_cat_id,$lang="en") 
{ 
    $records = $this->db 
      ->select(' 
       t1.id, 
       t1.date_received, 
       t1.customer_name, 
       t1.memo, 
       t1.percent_tax_withheld, 
       t1.gross_invoice_amount, 
       t1.tax_amount_withheld, 
       t1.net_amount_received, 
       t1.tax_payment_date, 
       t2.rate, 
       t3.name_' . $lang. ' AS deposit_account' 
       ) 
      ->from('brt AS t1') 
      ->join('exchange_rate AS t2', 't2.id = t1.exchange_rate_id','left') 
      ->join('balance_sheet_accounts AS t3', 't3.id = t1.deposit_account_id','left') 
      ->where('t1.income_statement_account_id', $id) 
      ->where('t1.tax_cat_id',$tax_cat_id) 
      ->where('t1.company_id', $this->session->userdata('company_id')) 
      ->where('t1.fiscal_year_id', $this->session->userdata('fiscal_year_id')) 
      ->where('t1.user_id', $this->m_auth->get_user_id()) 
      ->get(); 

    if ($records->num_rows() > 0) { 
     return $records; 
    } 
} 

может ли кто-нибудь помочь мне, как я могу написать, как эти запросы, которые должны быть безопасны из SQL-инъекций в Laravel Rloquent или Fluent.

ответ

2

попробуйте этот код: Я в основном из CI. Я сделал одну миграцию. Это может быть не лучшее решение. Я не тестировал.

DB::table('brt AS t1') 
    ->select('t1.id, 
       t1.date_received, 
       t1.customer_name, 
       t1.memo, 
       t1.percent_tax_withheld, 
       t1.gross_invoice_amount, 
       t1.tax_amount_withheld, 
       t1.net_amount_received, 
       t1.tax_payment_date, 
       t2.rate, 
       t3.name_' . $lang. ' AS deposit_account' 
      ) 
    ->leftjoin('exchange_rate AS t2', 't2.id', '=', 't1.exchange_rate_id') 
    ->leftjoin('balance_sheet_accounts AS t3', 't3.id', '=', 't1.deposit_account_id') 
    ->where('t1.income_statement_account_id', '=',$id) 
    ->where('t1.income_statement_account_id','=', $id) 
    ->where('t1.tax_cat_id','=',$tax_cat_id) 
    ->where('t1.company_id','=', $this->session->userdata('company_id')) 
    ->where('t1.fiscal_year_id','=', $this->session->userdata('fiscal_year_id')) 
    ->where('t1.user_id','=', $this->m_auth->get_user_id()) 
    ->get(); 
Смежные вопросы