'How to get name property from select option in laravel
I want to search from input field but want to get the property from the select option. Like I want mobile number to be searched from DB , but when i select mobile from select option then it should be search and if i select email then inside the input field i will post email and will select the email from select option then want to search. Here I have done some coding.
Blade file code
<select name="option" class="col-sm-4 form-control mg-md-l-2">
<option value="">Select</option>
<option value="cc" name="cc">Customer Code</option>
<option value="cname" name="cname">Company Name</option>
<option value="email" name="email">Email</option>
<option value="mobile" name="mobile">Phone</option>
</select>
<div class="col-1"></div>
<input type="text" class="col-sm-6 form-control" placeholder="Type here" name="">
Here the controller code
$user_id= Auth::user()->id;
$sale = $request->get('sales_id');
$priority = $request->get('priority');
$cc = $request->get('cc');
$cname = $request->get('cname');
$email = $request->get('email');
$mobile = $request->get('mobile');
$from_date = $request->input('from_date');
$to_date = $request->input('to_date');
if (empty($from_date)) {
$from_date = '2019-01-01 00:00:00';
} else {
$from_date = $from_date . ' 00:00:00';
}
if (empty($to_date)) {
$to_date = date('Y-m-d H:i:s');
} else {
$to_date = $to_date . ' 23:59:59';
}
if ($sale || $priority || $cname || $email || $mobile || $cc) {
$customers = \DB::table('field_customers as u')
->where('u.cc', 'LIKE', "%{$cc}%")
->where('u.sales_id', 'LIKE', "%{$sale}%")
->where('u.priority', 'LIKE', "%{$priority}%")
->where('u.cname', 'LIKE', "%{$cname}%")
->where('u.email', 'LIKE', "%{$email}%")
->where('u.mobile', 'LIKE', "%{$mobile}%")
->whereBetween('u.followup', [$from_date, $to_date])
->orderBy('u.followup', 'DESC')
->paginate(10);
}
else{
$customers = DB::table('field_customers')
->orderBy('id', 'DESC')
->paginate(20);
}
Solution 1:[1]
I have found a solution of this question and that is pretty much simple to work on. You can have a look here.
<select id="selector" onchange="DateCheck(this);"
class="form-control mg-md-l-2">
<option value="">All</option>
<option value="created_at">Entry Date</option>
<option value="visiting_date">Visiting Date</option>
<option value="followup">Follow-up Date</option>
</select>
<div id="created_at" style="display: none;">
<input type="date" class="form-control" id="created_at" name="created_at"
placeholder="Enter Entry Date" /><br />
</div>
<div id="visiting_date" style="display: none;">
<input type="date" class="form-control" id="visiting_date" name="visiting_date"
placeholder="Enter Visiting Date" /><br />
</div>
<div id="followup" style="display: none;">
<input type="date" class="form-control" id="followup" name="followup"
placeholder="Enter Followup Date" /><br />
</div>
<script type="text/javascript">
function DateCheck(that) {
if (that.value == "created_at") {
document.getElementById("created_at").style.display = "block";
} else {
document.getElementById("created_at").style.display = "none";
}
if (that.value == "visiting_date") {
document.getElementById("visiting_date").style.display = "block";
} else {
document.getElementById("visiting_date").style.display = "none";
}
if (that.value == "followup") {
document.getElementById("followup").style.display = "block";
} else {
document.getElementById("followup").style.display = "none";
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Joyanta sarkar |

