我在表中有unix时间戳,想要使用Carbon向用户显示.我怎样才能实现?
例如
1487663764.99256至
2017-02-24 23:23:14.654621
我想知道是否有一种方法可以使用CodeIgniter 2.0中的表单验证类来验证文件的大小.我有一个包含文件输入的表单,我想做这样的事情:
$this->form_validation->set_rule('file', 'File',
'file_type[image/jpeg|image/gif|image/png]|file_max_size[500]');
Run Code Online (Sandbox Code Playgroud)
我考虑扩展验证类,将其与上传类组合,并根据上传数据进行验证,但这可能非常耗时.
有没有人知道表格验证类的任何扩展会做这样的事情?
这就是我想要做的.这是控制器中的功能
public function get_started()
{
if(test_login($this->session->all_userdata())) {
$this->load->view('template');
} else {
$this->load->view('error');
}
}
Run Code Online (Sandbox Code Playgroud)
这是帮手
function test_login($sessdata)
{
if($sessdata->userdata('is_logged_in')) {
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我输入is_logged_in了一个布尔会话变量.但是,这不起作用.
我找不到错误.
我的视图有一个文件输入数组,如
<input type="file" name="videos[]" />
<input type="file" name="videos[]" />
...
...
Run Code Online (Sandbox Code Playgroud)
我想验证允许的总上传大小(例如:总允许上传限制为 3Mb)。我已经写了验证
$validatedData = $request->validate([
'videos.*' => 'present|file|mimetypes:video/mp4,video/ogg|max:3000',
]);
Run Code Online (Sandbox Code Playgroud)
但这验证了每个视频的 3Mb。
我试过了
$validatedData = $request->validate([
'videos' => 'file|max:3000',
'videos.*' => 'present|file|mimetypes:video/mp4,video/ogg|max:3000',
]);
/*------------------------------------------------*/
$validatedData = $request->validate([
'videos' => 'array|max:3000',
'videos.*' => 'present|file|mimetypes:video/mp4,video/ogg|max:3000',
]);
Run Code Online (Sandbox Code Playgroud)
但验证不适用于大于 3Mb 的总上传大小。我是否必须编写自定义验证规则来验证总上传文件大小限制。或者是否有任何预定义的验证规则?任何帮助表示赞赏。
谢谢你!
我正在尝试使用依赖于通知模型值的关系急切加载用户的通知:
$notifications = $user->notifications()
->with([
'notifiable' => function ($query) {
// Only load notifiable relation if notification 'notifiable_type' equals...
},
'notifiable.group:id,title' => function ($query) {
// Only load notifiable.group:id,title relation if notification 'notifiable_type' equals...
}
])
->get();
Run Code Online (Sandbox Code Playgroud)
问题是$query闭包内正在查询notifiable关系而不是通知模型本身......我显然错过了一些非常微不足道的东西。有什么建议?
所以我发现了一些问题,说你必须覆盖getAuthPassword()以从数据库中提供密码列的自定义名称.尝试将此方法与数据库中的列同名,并且无法正常工作.它仍然会发出此错误:未定义的索引:密码.
这是认证:
if (Auth::attempt(Input::only('user_displayName'), Input::get('user_password')))
Run Code Online (Sandbox Code Playgroud)
尝试在表单和控制器中将user_password更改为密码无效.
所以问题是,如果我在名为"user_password"的数据库中有一个列,是否有办法让Auth工作?
PS检查了我发现的每个旧解决方案
编辑
用户表的结构:
+======================+
| User |
+======================+
| user_id |
+----------------------+
| user_displayName |
+----------------------+
| user_fname |
+----------------------+
| user_lname |
+----------------------+
| user_email |
+----------------------+
| user_password |
+----------------------+
| created_at |
+----------------------+
| updated_at |
+----------------------+
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用jQuery和ajax函数上传图像,如何获取图像文件的所有细节,就像我们使用的php一样 $_FILE()
这是我的代码
JS
$("#uploadimg" ).click(function() {
$( "#file" ).click();
});
$( "#file" ).change(function(e) {
var file=$('#file').val();
alert(file);
die();
e.preventDefault();
$.ajax({
url:'http://localhost/JSG/blog/uploadimg',
secureuri:false,
type: "POST",
fileElementId:'image',
dataType: 'text',
data:{ file: file },
cache: true,
success: function (data){
alert(data);
console.log(data);
},
});
});
Run Code Online (Sandbox Code Playgroud)
调节器
public function uploadimg()
{
$var = $_POST['file'];
print_r($var);
if($this->input->post('file')) {
$config['upload_path'] = 'upload';
$config['file_name'] = $var;
$config['overwrite'] = 'TRUE';
$config["allowed_types"] = 'jpg|jpeg|png|gif';
$config["max_size"] = '1024';
$config["max_width"] = '400';
$config["max_height"] = '400';
$this->load->library('upload', $config);
if(!$this->upload->do_upload()) {
$this->data['error'] = …Run Code Online (Sandbox Code Playgroud) 我有一个名为“items”的表和一个名为“ref_code”的 where 条件的输入。
$items = DB::table('items')
->where('ref_code','=', $request->ref_code)
->get(['id', 'ref_code', 'name','price']);
Run Code Online (Sandbox Code Playgroud)
但我似乎无法获取每一列的值。
我使用以下方法检查了查询构建器是否工作:
return $items;
Run Code Online (Sandbox Code Playgroud)
幸运的是,没有问题。
但是返回或获取单个值不适用于:
return $items->id
Run Code Online (Sandbox Code Playgroud)
我的语法错了吗?所有这些都在我的控制器中。
编辑:我试过了
dd($items);
Run Code Online (Sandbox Code Playgroud)
在返回之前,它向我展示了这个:
Collection {#325 ?
#items: array:1 [?
0 => {#322 ?}
]
}
Run Code Online (Sandbox Code Playgroud) 我只是尝试了下面的代码,但它什么都不返回。
$view = \View::make('users.index', $data)->render();
Run Code Online (Sandbox Code Playgroud) laravel ×6
php ×5
codeigniter ×3
file-upload ×2
validation ×2
ajax ×1
controller ×1
database ×1
eloquent ×1
filesize ×1
javascript ×1
jquery ×1
laravel-5.4 ×1
morris.js ×1
php-carbon ×1
sql ×1