根据选择选项选择特定数据 [英] Select specific data based on select option
问题描述
我想在选择下拉列表中选择一个客户名称,并获取订单状态为0时的订单号
I want to select a customer name in a select dropdown list and gets its orders numbers where order status=0
在此订单上,它包含车辆列表,例如 T1,T2,T3 .....
On this order it contain a list of vehicles example T1,T2,T3.....
因此,在获得订单号之后,我得到了他的车辆清单.
So after getting the order number then I get his list of vehicles.
我希望有三个选择选项
我有相关表格
客户
Id
Name
客户订单
CustomerId
Vehiclenumber
Status
最后,我想在选择客户后存档车辆号.
Finally i want to archive the vehiclenumber after select customers.
推荐答案
所以您可以做的是
class Customer extends Model
{
public function orders()
{
return $this->hasMany(Order::class);
}
}
class Order extends Model
{
public function customer()
{
return $this->belongsTo(Customer::class);
}
}
在返回视图以选择客户名称的控制器方法中
In the controller method which returns the view to select Customer name
class CustomerController extends Controller
{
public function show()
{
return view('some.view', ['customers' => Customer::get(['id', 'name']);
}
}
使用 $ customers
填充视图中的选择选项.用户单击/选择用户后,如果您使用的是javascript框架,则通过ajax将请求发送到后端/服务器;如果您不使用javascript的框架,则通过纯POST请求.请记住传递访问者(用户)选择的用户的 id
.
Use the $customers
to populate select options in the view. Once user clicks/selects a user, send request to the backend/server via ajax if you are using a javascript framework or plain POST request in case you are not using javascript framework for frontend. Remember to pass the id
of the user selected by the visitor(user).
然后在控制器中处理请求
Then tackle the request in controller
class SomeController extends Controller
{
public function unfulfilledOrders(Request $request, $id)
{
$customer = Customer::findOrFail($id);
$orders = $customer->orders()->where('status', 0)->get();
return view('orders.show', ['orders' => $orders, 'customer' => $customer]);
}
}
然后使用 $ customer
和 $ orders
变量填充视图.
Then use the $customer
and $orders
variables to populate the view.
这篇关于根据选择选项选择特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!