小编sai*_*can的帖子

Laravel Distinct Count

有没有办法使用laravel使这个查询工作?DB :: raw或Eloquent用法无关紧要.

SELECT count(DISTINCT name) FROM tablename;
Run Code Online (Sandbox Code Playgroud)

这是我尝试但无法获得正确输出的内容:

EloquentTableName::select(DB::raw('count(DISTINCT name) as name_count'))->get();
Run Code Online (Sandbox Code Playgroud)

这会返回这样的东西,我想解决这个问题:

([{"name_count":"15"}])
Run Code Online (Sandbox Code Playgroud)

我只想得到15分.

php database laravel eloquent

18
推荐指数
3
解决办法
2万
查看次数

Laravel Mail ::发送如何将数据传递给邮件View

如何将数据从我的Controller传递到我的自定义邮件视图

这是我的控制器的发送邮件方法:

$data = array($user->pidm, $user->password);
Mail::send('emails.auth.registration', $data , function($message){
$message->to(Input::get('Email'), 'itsFromMe')
        ->subject('thisIsMySucject');
Run Code Online (Sandbox Code Playgroud)

这是我的emails.auth.registration 查看

<p>You can login into our system by using login code and password :</p>
<p><b>Your Login Code :</b></p> <!-- I want to put $data value here !-->
<p><b>Your Password :</b></p>   <!--I want to put $password value here !-->
<p><b>Click here to login :</b>&nbsp;www.mydomain.com/login</p>
Run Code Online (Sandbox Code Playgroud)

提前致谢.

php email laravel-4

7
推荐指数
2
解决办法
2万
查看次数

CKEditor插入HTML

  1. 我有来自数据库的数据.
  2. 在我的js文件中,我想更改我的CKEditor文本编辑器的值.
  3. 我的价值是原始的html.
  4. 我希望将这个原始值写在空的CKEditor文本编辑器上.

我试过这些但是一直有一个未定义的函数错误:

CKEDITOR.instances.myEditorID.insertHtml( '<p>This is a new paragraph.</p>' );
CKEDITOR.instances.myEditorID.setData( '<p>This is the editor data.</p>' );
Run Code Online (Sandbox Code Playgroud)

我也尝试了这个但仍未定义函数错误:

CKEDITOR.instances.YOUREDITORID.updateElement();
alert( document.getElementById( 'YOUREDITORID' ).value );
Run Code Online (Sandbox Code Playgroud)

而不是myEditorID,我试过'编辑','editor1','editor2',但仍然不适合我.

提前致谢.

---更新---

这是我的ckeditor文本编辑器的html:

<textarea id="myEditorID" name="myEditor"></textarea>
<script type="text/javascript">
    $(function () {
        var myEditor = $('#myEditorID');
        myEditor.ckeditor({ 
        height: 200, 
        extraPlugins: 'charcount', 
        maxLength: 2000, 
        toolbar: 'TinyBare', 
        toolbar_TinyBare: [
             ['Bold','Italic','Underline'],
             ['Undo','Redo'],['Cut','Copy','Paste'],
             ['NumberedList','BulletedList','Table'],['CharCount']
        ] 
        }).ckeditor().editor.on('key', function(obj) {
            if (obj.data.keyCode === 8 || obj.data.keyCode === 46) {
                return true;
            }
            if (myEditor.ckeditor().editor.document.getBody().getText().length >= 2000) {
                alert('You have reached …
Run Code Online (Sandbox Code Playgroud)

html javascript ckeditor

7
推荐指数
1
解决办法
2万
查看次数

Laravel updateOrCreate具有自动增量数据库

我的目的是更新值是否存在,否则在提交表单后在数据库表中插入新行.

问题是,这里的函数在db表中添加了新列而不是更新它们.

这是我的功能:

MyModel::updateOrCreate(array(
    'myField' => 'myValue',
))
    ->where('myAutoIncrementalField', '=', '5')
    ->where('myPrimaryKey', '=', '8');
Run Code Online (Sandbox Code Playgroud)

我的数据库表是这样的:
1.myPrimaryKey(不是自动增量,可以在模型上填充.)
2.myAutoIncrementalField(自动增量,不能在模型上填充.)

先感谢您.

mysql laravel eloquent

6
推荐指数
1
解决办法
2万
查看次数

如何使用Laravel,Bootstrap Modal和Ajax将数据发布和插入到数据库中

问题是我无法使用Input :: get()获取bootstrap modal textarea输入值,它返回null.

Modal的提交和文本输入(我的观点):

<button type="button" class="btn btn-danger" onclick="customModalSubmitFunction('modalID')">Submit</button>
Run Code Online (Sandbox Code Playgroud)

JS功能:

function customModalSubmitFunction(modalID){
    $.ajax({
        type: "POST",
        url: "urlRouteToController"
    });
}
Run Code Online (Sandbox Code Playgroud)

Route.php路线

Route::post('urlRouteToController', array(
    'uses' => 'myController@insertValueIntoDatabase',
    'as' => 'urlRouteToController'
));
Run Code Online (Sandbox Code Playgroud)

调节器

public function myController(){
   $dbModel = new Model;
   $dbModel->column1 = Input::get('textbox1');
   $dbModel->save();
}
Run Code Online (Sandbox Code Playgroud)

总之,我无法使用Input :: get('textbox1')获取发布的数据.但是将数据作为空值插入数据库(因为我无法获得文本框值)部分可行.

提前致谢.

php ajax jquery twitter-bootstrap laravel

5
推荐指数
0
解决办法
6933
查看次数

Laravel 多重验证器错误错误信息

问题:当上传的文件超过 5000kb 时,验证器返回 'required' 消息而不是 'max' 消息。为什么 ?

$file = (Input::file('inputName'));
$fileValidator = Validator::make(
   array('Field Name' => $file),
   array('Field Name' => 'required|max:5000|mimes:jpeg,png,bmp')
);

if($fileValidator->fails()){
   return $fileValidator->errors()->all(':message');
}
Run Code Online (Sandbox Code Playgroud)

更新:这个问题尤其发生在 *.psd 文件的验证上。


更新 2:当我 var_dump($file) 时,我可以看到;

object(Symfony\Component\HttpFoundation\File\UploadedFile)#9 (7) {
  ["test":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  bool(false)
  ["originalName":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  string(52) "4-47970_rsasecurityanalyticsevolutionofsiemebook.pdf"
  ["mimeType":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  string(24) "application/octet-stream"
  ["size":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  int(0)
  ["error":"Symfony\Component\HttpFoundation\File\UploadedFile":private]=>
  int(1)
  ["pathName":"SplFileInfo":private]=>
  string(0) ""
  ["fileName":"SplFileInfo":private]=>
  string(0) ""
}
Run Code Online (Sandbox Code Playgroud)

如您所见, pathName 和 fileName 看起来为空。所以这就是为什么 laravel 返回所需的消息。这是新问题:为什么 fileName 为 null ?

php laravel laravel-4

5
推荐指数
1
解决办法
531
查看次数

Twitter bootstrap水平中间对齐容器

我有问题集中我的容器.

<div class="row centered-form center-block">
    <div class="container col-md-10">
        <ul class="nav nav-tabs" id="projectTabs">
            <li role="presentation" class="active"><a href="#tab1" data-toggle="tab">Tab1</a></li>
            <li role="presentation"><a href="#Tab2" data-toggle="tab">Tab2</a></li>
        </ul>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

主行的中心宽度约为65%,但是包含导航标签容器会在左侧的主行中粘贴.

先感谢您.

css twitter-bootstrap

4
推荐指数
1
解决办法
1万
查看次数

使用charcount插件的Ckeditor字符限制

如何达到最大字符限制阻止用户输入新字符?

Ckeditor charcount插件只显示剩余的字符,我希望它停在0.但它会减去整数.

这是我的HTML代码.

<textarea id="myTextEditor1" name="myTextEditor"></textarea>
<script type="text/javascript">
        CKEDITOR.replace('myTextEditor1', { 
            height: 200, 
            extraPlugins: 'charcount', 
            maxLength: 10, 
            toolbar: 'TinyBare', 
            toolbar_TinyBare: [
                 ['Bold','Italic','Underline'],
                 ['Undo','Redo'],['Cut','Copy','Paste'],
                 ['NumberedList','BulletedList','Table'],['CharCount']
            ] 
        });
</script>
Run Code Online (Sandbox Code Playgroud)

我必须使用onChange插件吗?如果我必须如何限制用户输入新字符?

javascript jquery event-handling ckeditor

4
推荐指数
1
解决办法
1万
查看次数

使用变量构建 Laravel 查询

假设我有像 $var1 和 $var2 这样的变量。

假设我想要一个类似的查询

$myQuery = DB::table('myTable')
           ->where('firstField', '=', $var1)
           ->where('secondField', '=', $var2)
           ->get();
Run Code Online (Sandbox Code Playgroud)

当然,当我的变量为空时,这个不起作用。我想控制它们,如果它们为空就做点什么。

我应该根据这些变量创建一个查询,并用它们所持有的值过滤它们。

任何其他想法如何做到这一点?

php mysql laravel eloquent

2
推荐指数
1
解决办法
3875
查看次数

验证码刷新(mewebstudio)

目的:刷新验证码图像。

routes.php

Route::get('/get_captcha/{config?}', function (\Mews\Captcha\Captcha $captcha, $config = 'default') {
    return $captcha->src($config);
});
Run Code Online (Sandbox Code Playgroud)

验证码图片(mypage.blade.php):

<img src="{{ Captcha::img() }}" alt="captcha" class="captcha-img" data-refresh-config="default">
Run Code Online (Sandbox Code Playgroud)

js文件:

$(document).ready(function(){
    $('img.captcha-img').on('click', function () {
        var captcha = $(this);
        var config = captcha.data('refresh-config');
        //console.log(config);
        $.ajax({
            method: 'GET',
            url: '/get_captcha/' + config,
        }).done(function (response) {
            captcha.prop('src', response);
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

问题: 控制台上的js ajax错误:http://localhost/get_captcha/default 404错误。

参考:https : //github.com/mewebstudio/captcha/issues/54#issuecomment-141483501

附加信息:我在Laravel 4上使用了验证码,但是src在上面的行中找不到名为的方法$captcha->src($config)

先感谢您。

php ajax jquery captcha laravel-4

2
推荐指数
1
解决办法
3734
查看次数