So i have a controller with a basic search function and i want to know when a user click the search button if there is data exist i want it to return the same page with error message, but if data not exist i want return another page. how can i do that? my code as below:
controller:
public function search(Request $request, $companyID, $entityType)
{
$data = [];
$intentTypes = DiraQuestion::select('intent')->where('company_id', $companyID)->groupBy('intent')->get();
foreach ($intentTypes as $intent)
{
$data[$intent->intent] = $intent->intent;
}
$q = $request->q;
$user = DiraQuestion::select('eVal')->where('company_id', $companyID)->where('eType', $entityType)->where('eVal','LIKE','%'.$q.'%')->groupBy('eVal')->get();
return view('AltHr.Chatbot.addType', compact('data','entityType','companyID'))->withDetails($user)->withQuery($q);
}
my current view page which shows if exist and if not exist shows form:
@if(isset($details))
<div class="container-fluid container-fixed-lg">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<!-- <div class="panel-heading">
<div class="panel-title"><b></b></div>
<div class="clearfix"></div>
</div> -->
<div class="panel-body">
<div class="form-group edit-response-container">
<div class="col-md-12">
@foreach($details as $user)
<p><span style="color:red;"></span> is already included!</p>
@endforeach
</div>
@if($details->isEmpty())
<form action="" method="post">
<!-- @if(empty($data))
<p>No predefined intents.</p>
@else -->
<div class="col-md-12">
<div class="form-group form-group-default required">
<label>New Type</label>
<input type="text" class="form-control" name="entityValue" placeholder="" value="" required readonly/>
</div>
</div>
<!-- <div class="col-md-12">
<div class="form-group form-group-default required">
<label>New Question</label>
<input type="text" class="form-control" name="question" placeholder="Enter Sample Question" required>
</div>
</div>
<div class="col-md-12">
<div class="form-group form-group-default required">
<label>Intent</label>
<select class="full-width" name="intent" data-init-plugin="select2" required>
<option selected disabled></option>
@foreach($data as $datas)
<option value=""></option>
@endforeach
</select>
</div>
</div> -->
<div class="col-md-12">
<div class="new-field">
<div class="form-group-attached">
<div class="form-group form-group-default required">
<label>Synonyms:</label>
<input type="text" class="form-control" name="syn" placeholder="Enter Synonyms" />
</div>
</div>
</div>
<p><i>*Enter All Synonyms Separating With ','</i></p>
</div>
<div class="col-md-12">
<br>
<!-- <button type="button" class="btn alt-btn-green alt-btn btn-xs add-new">Add Synonym</button> -->
<button type="submit" class="btn alt-btn-green alt-btn btn-xs">Save</button>
<a href="" class="btn alt-btn-green alt-btn btn-xs">test</a>
</div>
@endif
</form>
@endif
</div>
</div>
</div>
</div>
</div>
</div>
@endif
as you can see currently if data exist, it shows error message on the same page, but if no data it shows a form on the same page itself.. i want it to route to another page when there is no data found.
Aucun commentaire:
Enregistrer un commentaire