Mohamed Shaheen
Mohamed Shaheen

Reputation: 663

API request with multiple body inputs

I am new to laravel this is how I make an API with one single body item

$shops_categories=ShopsCategories::all()->where('title',$request->title);

how to request more than an item in the body for example title , email , password ?

Upvotes: 1

Views: 76

Answers (4)

Luciano
Luciano

Reputation: 2196

Eloquent allows you to chain as many where as required. So you are able to do

$shops_categories = ShopsCategories::where('title',$request->title)->where('email',$request->email)->where('password',$request->email)->get();

Upvotes: 1

Poldo
Poldo

Reputation: 1932

You can also convert request to array using all()

//$request->all() is same as ['title'=> 'my title', ...]

$shops_categories=ShopsCategories::where($request->all())->get();

Upvotes: 0

Ranganath D T
Ranganath D T

Reputation: 3

i guess you are performing query operation in controller itself which is not recommended,please create an instance for the model and make a function call to model and in the model you can return like

return $this::where('id','=',$id)->get()

and also please try to avoid using text/string in where condition instead use id's or unique values

Upvotes: 0

Pavel Lint
Pavel Lint

Reputation: 3527

You can do it like so:

$cats = ShopsCategories::query()->where(['title' => $title, 'email'=>$email, 'name'=>$name]);

Upvotes: 1

Related Questions