How to structure multiple PHP queries

时间:2017-06-12 16:45:42

标签: php sql

I just had a question regarding how to structure a line of code that gathers all of the objects of my Task objects into my array based on a couple of conditions aka multiple queries.

What I want to do is gather all of the objects with certain department names and certain full names that are inputted by my user in another html file.

So far, it stores and displays the correct objects for departments but I can't seem to figure out how to add a full name filter too... Here's what I have so far but I can't find anything on the Internet regarding if this is correct syntax to have multiple queries. Thank you! :)

$tasks = Task::where('department',$request['selected'])->where('name'.' '.'last_name', $request['full_name'])->paginate(5);

1 个答案:

答案 0 :(得分:1)

You can't just append columns but you could separate the full name into first name and last name as following:

$fullName = explode(' ', $request['full_name']);
$firstName = $fullName[0];
$lastName = $fullName[1];
$tasks = Task::where('department',$request['selected'])->andWhere('name', 
$firstName)->andWhere('last_name', $lastName)->paginate(5);