Take a variable from the url, pass method get Laravel

Asked

Viewed 393 times

0

How do I get this function to take the values of the url passed by method get

 public function searchBy($nome, $situacao){
     $params['nome'] = array('value'=>'%' . $nome . '%', 'operador'=>'like');
     $params['situacao'] = array('value'=>$situacao, 'operador'=>'=');

     return $this->search($this->cliente, $params);
 }
  • It seems to me that this $this->search is very conducive to SQL injection. Why not use Eloquent?

  • it seems that this $this->search is a method that passes only the model and the arguments from within the where() of eloquent

1 answer

2

You can import the class Illuminate\Http\Request in his controller and uses it in its method to receive the data passed by the request to your controller, by route:

use Illuminate\Http\Request;

public function searchBy(Request $request){
    $params = [
        'nome' => ['value' => "%{$request->input('nome')}%", 'operador' => 'like'],
        'situacao' => ['value' => $request->input('situacao'), 'operador' => '='],
    ];

    return $this->search($this->cliente, $params);
}
  • $request->nome also works in Laravel 5 up.

  • Yeah, sure, but how imput() is more generic and even compatible with Laravel 6 (which will remove the class Imput).

  • Did not work my codes are ai public Function search1(){ Return view('client.search')->with(['name' =>'' ,'situacao'=> ''']); } public Function searchBy($name ,$situacao){ $params['name'] = array('value'=>'%' . $name. '%', 'operator'=>'like'); $params['situacao'] = array('value'=>$situacao, 'operator'=>'='); Return $this->search($this->client, $params); ; }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.