mardi 10 mai 2022

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);
    }

Here what I want enter image description here



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/B5owHMs
via IFTTT

Aucun commentaire:

Enregistrer un commentaire