我有两个相关的模型:Category和Post.
该Post模型具有published范围(方法scopePublished()).
当我尝试获取该范围的所有类别时:
$categories = Category::with('posts')->published()->get();
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
调用未定义的方法
published()
类别:
class Category extends \Eloquent
{
public function posts()
{
return $this->HasMany('Post');
}
}
Run Code Online (Sandbox Code Playgroud)
帖子:
class Post extends \Eloquent
{
public function category()
{
return $this->belongsTo('Category');
}
public function scopePublished($query)
{
return $query->where('published', 1);
}
}
Run Code Online (Sandbox Code Playgroud) 是否有可能使用ref与el-input组件从元素的UI?我试图$refs在安装我的Vue实例时专注于输入.这是我的代码:
<div id="app">
<el-input type="text" ref="test" placeholder="enter text"></el-input>
</div>
Run Code Online (Sandbox Code Playgroud)
在我的Vue实例中:
new Vue({
el: "#app",
mounted(){
this.$refs.test.focus()
}
})
Run Code Online (Sandbox Code Playgroud)
该focus方法根本不起作用,即使我this.$refs.test.focus()进入一个方法并试图通过一个事件触发它.
我在管理区域中有一个表单,用户可以在其中输入包含短代码的文本:
在[temp c = 200]加热烤箱
我想要的是temp在前端显示时要解析并转换为Vue 2组件的短代码.
这是一个简化的Temperature.vue组件:
<template>
<span class="temperature">
{{ celsius }}°C
</span>
</template>
<script>
import { mapGetters, mapActions } from 'vuex'
export default {
props: ['celsius'],
name: 'temperature'
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是一个简化的Instructions.vue组件,它将使用短代码解析和呈现文本:
<template>
<div v-html="parseShortcodes(text)"></div>
</template>
<script>
import ShortcodeParser from 'meta-shortcodes'
import Temperature from 'Temperature.vue'
export default {
data: () => {
return {
text: 'Heat oven at [temp c=200]',
parser: ShortcodeParser()
}
},
components: [
Temperature
],
methods: {
parseShortcodes(text) { …Run Code Online (Sandbox Code Playgroud) 我已经设置了一个Mandrill webhook,它会在电子邮件遭到硬弹跳或被拒绝时更新我的应用程序,因此我不会将该特定电子邮件地址保留在我的数据库中.它的工作方式是:用户给我一个地址,我发给他一个确认,如果我没有在30分钟内听到Mandrill的webhook,我认为没关系.
所以我用不存在的地址运行了一些测试,但它们并没有太顺利.在我认为他们没事的很长时间之后,他们中的大多数都出现了几个小时.
另外,我没有说明接收webhook批次的延迟.根据出站活动日志,一封邮件在下午2:01反弹,但是webhook历史记录显示批次仅在下午2:52发送.
我的问题是:为了让Mandrill有足够的时间来检测硬反弹/拒绝然后向我发送webhook批次,我应该延迟我的应用程序的可传递性假设多长时间?由于延迟处理高峰时间或其他特殊事件,我可以忍受大约5%的糟糕电子邮件,但看起来我的30分钟还不足以捕捉到任何东西......
当我试图在localhost(php版本:PHP 5.6.4-4ubuntu6.4(cli))上运行Task Schedular时,它运行正常.
crontab中
* * * * * php /home/aishatest/public_html/Aisha/Aisha/artisan schedule:run >> /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)
应用程序/软件/ Kernel.php
<?php
namespace App\Console;
use App\Console\Commands\CheckOutfitAvailibilityCommand;
use App\Http\Controllers\OutfitCronController;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
// Commands\Inspire::class,
CheckOutfitAvailibilityCommand::class
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
{
\Log::error("Kernel");
//$schedule->command('inspire') …Run Code Online (Sandbox Code Playgroud) 我设法使用该name属性创建了直接自嵌套的组件,并且一切运行正常。
<template>
<div>
<span>Hi, I'm component A!</span>
<component-a></component-a>
</div>
</template>
<script>
export default {
name: 'component-a',
components: {
'component-a': this
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
现在,我想创建间接的自嵌套组件。像这样:
ComponentA.vue:
<template>
<div>
<span>Hi, I'm component A!</span>
<component-b v-if="hasItems" v-for="item in items" :item="item"></component-b>
</div>
</template>
<script>
import ComponentB from './ComponentB.vue'
export default {
name: 'component-a',
components: {
'component-b': ComponentB
},
props: ['items'],
computed: {
hasItems() {
return this.items.length > 0
}
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
ComponentB.vue:
<template>
<div>
<span>Hi, I'm component B!</span>
<component-a v-if="hasItems" :items="item.items"></component-a> …Run Code Online (Sandbox Code Playgroud) 我有一个使用Laravel 5.2构建的Web应用程序,我的问题是如何存储然后显示表情符号。当我使用iPhone上的表情符号时,例如,在保存数据库后返回fire?。我已经设置了'charset'='utf8mb4'; '排序规则'='utf8mb4_unicode_ci'
但仍然得到相同的结果。我需要安装软件包或其他东西吗?
I'm using Webpack 2 (via Laravel Mix) to compile a Javascript asset in different languages, much like Webpack's own i18n plugin. I've built a custom implementation, though, which plays nicely with Mix's helpers. There is one final issue, though, which I cannot wrap my head around, which has to do with the watch process. Here's a summary of what is happening:
我正在尝试使用Vue 2进行可编辑的组件.它应该contenteditable在任何标记中使用该属性,替换正常输入.我想给它一个占位符功能,以便在用户没有提供时显示一个值,但我似乎无法让它工作.
我正在观察组件的当前值,并设置data.isEmpty为true没有用户内容时.然后该组件应显示占位符值,但目前它不显示任何内容.
如果我console.log是render方法的结果,它将显示占位符子节点被正确实例化,但由于某种原因它只是不会显示在最终的HTML上.
这是一个JSFiddle:https://jsfiddle.net/dy27fa8t/
并为喜欢它的人提供了一个嵌入式代码:
Vue.component('editable-content', {
props: {
initial: {
type: String
},
placeholder: {
type: String,
required: false
}
},
data() {
return {
value: this.initial,
isEmpty: this.initial === ''
}
},
render: function(createElement) {
const self = this
return createElement(
'div', {
attrs: {
contenteditable: true
},
on: {
input: function(event) {
self.value = event.target.innerHTML
self.$emit('edited', event.target.value)
}
}
},
this.isEmpty ? this.placeholder : …Run Code Online (Sandbox Code Playgroud)所以我有两个表,组织和联系人。两个表都有“电子邮件”列,我需要做的是保留组织的名称,但在电子邮件列中连接所有电子邮件(组织+所有联系人电子邮件)。
这是我尝试过的一些版本,但没有成功
1)这个不分组:
$customers = DB::table('customers')
->whereRaw('LENGTH(customers.email) > 4')
->select([
'customers.id',
'customers.name',
'customers.email'
]);
$contacts = DB::table('contacts')
->whereRaw('LENGTH(contacts.email) > 4')
->leftJoin('customers', 'contacts.customer_id', '=', 'customers.id')
->select([
'customers.id',
'customers.name',
'contacts.email'
]);
return $customers
->union($contacts)
->select([
'id',
'name',
DB::raw('GROUP_CONCAT(DISTINCT email, ", ") AS emails'),
])
->groupBy('id')
->get();
Run Code Online (Sandbox Code Playgroud)
2)这个实际上非常接近,但它不会过滤掉联系人或客户整体都没有的条目DB::raw('LENGTH(email) > 4')
return $customers = DB::table('customers')
->leftJoin('contacts', 'contacts.customer_id', '=', 'customers.id')
->select([
'customers.id',
'customers.name',
'registration',
DB::raw('GROUP_CONCAT(DISTINCT contacts.email, ", ") AS contact_emails'),
'customers.email'
])
->groupBy('customers.id')
->get();
Run Code Online (Sandbox Code Playgroud)
3)我尝试更接近子查询(我知道它只会过滤掉没有电子邮件的联系人)
3.1) 尝试子查询 1 会导致错误:JoinClause::whereRaw()不存在
return $customers = …Run Code Online (Sandbox Code Playgroud)