我需要在Laravel中按创建日期搜索记录
我的用户模型
editorial_form .vue
我的UserController
<template>
<v-layout justify-center align-center >
<form-component :source='source' :form='form'>
<div slot='content-form'>
<v-text-field v-model='form.name' :rules="nameRules" ></v-text-field>
</div>
</form-component>
</v-layout>
</template>
<script>
import formComponent from "../utilities/form.vue"
export default {
data: () => ({
source:{
title:'Add Author',
create:'admin/Authors',
method:'post',
return:'/Authors'
},
form:{
name:''
},
nameRules:[
v=> /^[A-Za-z\s]*$/gi.test(v) || 'sorry, the only letters ',
v=> !!v || 'sorry, the name es rquired'
],
}),
beforeMount(){
if(this.$route.meta.mode === 'edit') {
this.source.title = 'Edit author'
this.source.create = 'admin/Authors/' + this.$route.params.id
this.source.method = 'put'
this.form.name=this.$route.params.name
}
},
components:{
formComponent
}
}
</script>
视图
public function scopeCreate_at($query, $created_at){
if($created_at)
return $query->whereRaw('created_at', 'LIKE', "%$created_at%");
}
但是,当我重新加载页面时,我有这个
class UserController extends Controller
{
public function index(Request $request){
$name = $request->get('name');
$email = $request->get('email');
$bio = $request->get('bio');
$created_at = $request->get('created_at');
$users = User::orderBy('id', 'DESC')
->name($name)
->email($email)
->bio($bio)
->created_at($created_at)
->paginate(10);
return view('user', compact('users'));
}
其他方法效果很好
答案 0 :(得分:2)
'created_at' !== 'create_at'
scopeCreate_at
更新:
public function scopeCreate_at
scopeCreate_at
更新:
...Create_at
更新:
lagbox向OP传递字母'd'
,并说:“您放了这个”
但是,认真的说,您可以命名函数scopeCreated_at
或通过命名函数create_at
来调用作用域以解决该问题。