问题
I have been searching for long time to make work using prettus/l5-repository but none of things that I tried worked.
My problem is that I need to format get request url like
?search=name:John Doe;email:john@gmail.com
when user click submit button.
I have tried to replace request()->query->all()
to "search"=>"name:John Doe;email:john@gmail.com"
but it did not work. I believe request's GET URL should be that format.
How to format request URL like that?
Controller index()
$paginator = $this->Repository->scopeQuery(function ($query) {
return $query->orderBy('updated_at', 'desc');
})->paginate($limit, ['*']);
$paginator->appends(request()->query->all()); //Append Url query
Blade
<form method="GET" action="{{Request::fullUrl()}}">
<div class="btn-group pull-left" style="padding-left: 0;">
<a href="{{request()->url().'/create'}}" class="btn btn-success"><span
class="glyphicon glyphicon-plus" aria-hidden="true"></span>Create Case</a>
</div>
<div id="filterDropDown" class="btn-group col-md-3">
<button type="button" class="btn btn-info dropDownTitle">Filter</button>
<button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
<span class="sr-only">Toggle Dropdown</span>
</button>
<ul class="dropdown-menu" style="left:14px">
<li value="All"><a href="#">All Record</a></li>
<li value="Waiting"><a href="#">Waiting</a></li>
<li value="Resolved"><a href="#">Resolved</a></li>
</ul>
<input type="text" name="status" value="{{Request::get('search')}}" style="visibility: hidden"/>
</div>
<div class="input-group col-md-7 pull-right">
<input type="text" name="title" class="form-control" id="basic-url"
aria-describedby="basic-addon3" value="{{Request::get('search')}}"
placeholder="Search by Title or Case number">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">Search</button>
</span>
</div>
<div class="clear"></div>
</form>
回答1:
Your search are a string, then you need explode ";".
$search = explode(';', request()->query->get('search'));
$final_search = "search=";
foreach($search as $key => $value) {
$final_search .= $value . ";";
}
then pass $final_search to your view
来源:https://stackoverflow.com/questions/35995136/formatting-request-url-in-laravel-blade