有没有更好的方法来填写上述搜索表单中的表单输入值?
Is there any better way to fill form input values in the above search form?
我有一个如下所示的搜索表单,只有一个字段
{!! Form::open(array('method' => 'POST',
'action' => 'CustomerController@SearchCustomers',
'class' => "form-horizontal form-label-left")) !!}
{!! csrf_field() !!}
<input type="text" class="form-control" name="Customer">
<button type="submit">Search</button>
{!! Form::close() !!}
控制器中的代码如下
$AllCustomers = \App\Models\Customer_Model
::where('Customer', 'LIKE', '%'.$Customer.'%')
->get();
return View('Customer.List', array('AllCustomers' => $AllCustomers));
我在尝试什么?
提交表单进行搜索时,在视图中,我应该能够再次在文本框中查看关键字。为此,我在下面做了。
return View('Customer.List', array('AllCustomers' => $AllCustomers, 'Key' => $Customer));
现在在表格中,我在下面做。
<input type="text" class="form-control" name="Customer" value="{{$Key}}">
问题
有没有更好的方法来填写上述搜索表单中的表单输入值?
我认为这可能是您正在寻找的机器人:
use Illuminate\Http\Request;
class MyController extends Controller
{
/**
* My action.
*
* @param Request $request
* @return View
*/
public function index(Request $request)
{
...
return View('Customer.List', array_merge(
['AllCustomers' => $AllCustomers],
$request->only(['Customer'])
));
}
action 方法中的 use
行和 type-hinted 参数执行 Request 对象的依赖注入。
将 $request->only(['Customer'])
合并到您的视图参数中可为您提供所需的 "with input" 功能。
Laravel 文件: https://laravel.com/docs/master/requests
我认为正确的方法是使用输入内联检查 $request->input('key', null)
检查请求中是否存在密钥,如果是,它将 return 为空,否则 return 密钥,检查下面的代码。
控制器:
public function index(Request $request)
{
$key = $request->input('key', null);
$allCustomers = \App\Models\Customer_Model
::where('Customer', 'LIKE', '%'.$Customer.'%')->get();
return View('Customer.List', compact('allCustomers', 'key'));
}
查看:
<input type="text" class="form-control" name="Customer" value="{{is_null($key)?'':$key}}">
希望对您有所帮助。
我有一个如下所示的搜索表单,只有一个字段
{!! Form::open(array('method' => 'POST',
'action' => 'CustomerController@SearchCustomers',
'class' => "form-horizontal form-label-left")) !!}
{!! csrf_field() !!}
<input type="text" class="form-control" name="Customer">
<button type="submit">Search</button>
{!! Form::close() !!}
控制器中的代码如下
$AllCustomers = \App\Models\Customer_Model
::where('Customer', 'LIKE', '%'.$Customer.'%')
->get();
return View('Customer.List', array('AllCustomers' => $AllCustomers));
我在尝试什么?
提交表单进行搜索时,在视图中,我应该能够再次在文本框中查看关键字。为此,我在下面做了。
return View('Customer.List', array('AllCustomers' => $AllCustomers, 'Key' => $Customer));
现在在表格中,我在下面做。
<input type="text" class="form-control" name="Customer" value="{{$Key}}">
问题
有没有更好的方法来填写上述搜索表单中的表单输入值?
我认为这可能是您正在寻找的机器人:
use Illuminate\Http\Request;
class MyController extends Controller
{
/**
* My action.
*
* @param Request $request
* @return View
*/
public function index(Request $request)
{
...
return View('Customer.List', array_merge(
['AllCustomers' => $AllCustomers],
$request->only(['Customer'])
));
}
action 方法中的 use
行和 type-hinted 参数执行 Request 对象的依赖注入。
将 $request->only(['Customer'])
合并到您的视图参数中可为您提供所需的 "with input" 功能。
Laravel 文件: https://laravel.com/docs/master/requests
我认为正确的方法是使用输入内联检查 $request->input('key', null)
检查请求中是否存在密钥,如果是,它将 return 为空,否则 return 密钥,检查下面的代码。
控制器:
public function index(Request $request)
{
$key = $request->input('key', null);
$allCustomers = \App\Models\Customer_Model
::where('Customer', 'LIKE', '%'.$Customer.'%')->get();
return View('Customer.List', compact('allCustomers', 'key'));
}
查看:
<input type="text" class="form-control" name="Customer" value="{{is_null($key)?'':$key}}">
希望对您有所帮助。