我有一个问题对你来说可能听起来很傻,所以请原谅我.
我不确定何时使用routes/api.php文件.
如果我想从带有ajax的数据表中删除记录,我是否需要创建一个单独的控制器并将路径放在api.php中,或者我可以使用我用于其他所有的相同控制器并将路由放在web.php中?
我正在努力学习Laravel.
我安装它并创建了一个项目.
使用Netbeans我在项目名称上看到一个错误标记,上面写着:
缺少npm模块.
我安装了node.js,点击了resolve,将路径指向node.exe和npm.cmd
我仍然看到错误,NetBeans说:
npm(myproject)正在运行.
错误仍然存在,但现在当我点击时Resolve,句子"Missing npm modules"显示为灰色,Resolve按钮不执行任何操作.
还有什么我应该做的吗?
我需要用Laravel来完成所有这些吗?
我可以继续使用此错误进行开发吗?
我正在使用 Laravel 5.4。
我的表单中有两个字段:travel_km 和travel_rate
我的规则: 'travel_km' => 'numeric|nullable', 'travel_rate' => 'sometimes|required_with:travel_km'
问题是,如果travel_km 为空,我仍然会在travel_rate 上收到错误,因为它为空。
如果我在 Travel_rate 上设置可为空,即使 Travel_km 不为空,我也不会收到错误。
为了解决这个问题,我在控制器中这样做了:
if(empty($request->travel_km) && empty($request->travel_rate)) {
$this->validate($request,
[
'customer_id' => 'required',
'service_date' => 'required',
'labour_hrs' => 'numeric|nullable',
'hourly_rate' => 'sometimes|required_with:labour_hrs',
],
[
'customer_id' => 'Please enter the customer',
'service_date' => 'Please select the service date',
'labour_hrs' => 'Please enter a valid number',
'hourly_rate' => 'Please enter a valid number',
]);
} else {
$this->validate($request,
[
'customer_id' => 'required',
'service_date' …Run Code Online (Sandbox Code Playgroud) 使用 Laravel 5.4,仅当 role_id 字段不是 999 时,我才需要验证用户表上的电子邮件字段是否唯一。
在注册控制器中,我这样做了:
return Validator::make($data, [
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'email' => [
'required',
'email',
'max:255',
Rule::unique('users')->where(function($query) {
$query->where('role_id', '<>', 999);
})
],
'phone' => 'required|phone',
'password' => 'required|min:6|confirmed'
]);
Run Code Online (Sandbox Code Playgroud)
但是当我尝试注册时出现此错误:
找不到类“App\Http\Controllers\Auth\Rule”
我究竟做错了什么?
谢谢
我是vue的新手,我想要一些帮助从输入字段获取值的方法:
以我的形式,我有:
<input type="hidden" id="groupId" value="1">
Run Code Online (Sandbox Code Playgroud)
使用jQuery,我可以做到:
var group_id = $('#groupId').val();
Run Code Online (Sandbox Code Playgroud)
在Vue中,我不知道如何绑定隐藏字段:
<div id="app">
<input type="text" v-model="groupId"> //Where do I put the value?
</div>
new Vue({
el: '#app',
data: {
groupId: //What do I put here to get the field's value?
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?