我有两个表具有一对一的关系,由外键约束设置。我想将onDelete规则设置为“设置默认值”,这意味着当删除外部表上的一行时,参考值将恢复为其默认值。这是我的代码:
游览表:
Schema::create('tours', function (Blueprint $table) {
$table->increments('id')->unsigned()->index();
$table->integer('grade')->unsigned()->default(1);
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
成绩表:
Schema::create('grades', function(Blueprint $table){
$table->increments('id')->unsigned()->index();
$table->string('name');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
设置外键:
Schema::table('tours', function (Blueprint $table) {
$table->foreign('grade')->references('id')->on('grades')->onDelete('set default');
});
Run Code Online (Sandbox Code Playgroud)
当我运行迁移时,它没有错误。但是,查看HeidiSQL中的表,该表无法正常工作。外键已设置,但是onDelete属性仅显示“ NO ACTION”。
随后,当我删除成绩表中的一行时,出现外键约束错误。
我究竟做错了什么?
我有一个时间表,用于向客户收费。它将来自 Toggl 的条目记录为小时分数,即 35 分钟记录为 0.58。我想把这个数字四舍五入到最接近的 0.25,即。最近的一刻钟。这在谷歌表格中可能吗?
我有一个看起来像这样的数组:
$myArray = array(
'firstRow' => array(
0 => array(
'id' => 1
'title' => 'First Cat.'
),
1 => array(
'id' => 2
'title' => 'Second Cat.'
)
),
'SecondRow' => array(
0 => array(
'id' => 3
'title' => 'Third Cat.'
),
1 => array(
'id' => 4
'title' => 'Fourth Cat.'
)
)
);
Run Code Online (Sandbox Code Playgroud)
这将传递给我的刀片模板.我可以使用原始的php回声值:
<?php echo $myArray['firstRow'][0]['title'] ?>
Run Code Online (Sandbox Code Playgroud)
哪个按预期工作.但是,当我尝试使用刀片的语法执行我认为完全相同的操作时:
{{ $myArray['firstRow'][0]['title'] }}
Run Code Online (Sandbox Code Playgroud)
我收到错误:
试图获得非对象的属性
?
我正在使用Laravel 5的belongsToMany方法来使用中间数据透视表定义相关表。我的应用程序使用的是雄辩的模型Tour和TourCategory。在游览模型中,我有:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Tour extends Model
{
public function cats(){
return $this->belongsToMany('App\TourCategory', 'tour_cat_assignments', 'tour_id', 'cat_id');
}
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中,我使用Laravel的with方法从巡回表中检索所有数据以及关联的类别数据:
$tours = Tour::with('cats')->get();
Run Code Online (Sandbox Code Playgroud)
一切正常。问题是我不希望类别数据具有其当前的原始格式,因此我需要先对其进行重新排列。但是,如果不cats先取消设置,就无法覆盖该属性:
public function serveTourData(){
$tours = Tour::with('sections', 'cats')->get();
foreach($tours as $tour){
unset($tour->cats); // If I unset first, then it respects the new value. Why do I need to do this?
$tour->cats = "SOME NEW VALUE";
}
Log::info($tours);
}
Run Code Online (Sandbox Code Playgroud)
有人可以解释其背后的逻辑吗?
我知道在SO中已经有一些关于这个错误的问题,但没有一个有任何有见地的答案。
我有 2 个并排组件,我试图在路由之间导航时为它们的宽度设置动画。我的路由配置如下所示:
export const routes = [
{ path: '', component: IndexComponent, children:
[
{ path: 'home', children:
[
{ path: '', component: FirstComponent, outlet: 'first', data: { state: 'a' } },
{ path: '', component: SecondComponent, outlet: 'second', data: { state: 'b' } }
]
},
{ path: 'about', children:
[
{ path: '', component: FirstComponent, outlet: 'first', data: { state: 'b' } },
{ path: '', component: SecondComponent, outlet: 'second', data: { state: 'a' …Run Code Online (Sandbox Code Playgroud) 我正在使用组件工厂来动态生成动态组件。向工厂传递一个数据数组,其中包括生成组件的输入参数:
<app-field-factory [componentData]="componentSeedData"></app-field-factory>
Run Code Online (Sandbox Code Playgroud)
这工作正常,“现场工厂”组件处理数据。在每个生成的组件中我都有这样的东西:
export class TextInputComponent implements OnInit {
@Input() id: number;
@Input() field_name: string;
@Input() parent: string;
@Input() validators: {};
public fieldForm: FormGroup;
constructor(
private injector: Injector,
private formBuilder: FormBuilder,
) {
this.id = this.injector.get('id');
this.field_name = this.injector.get('field_name');
this.parent = this.injector.get('parent');
this.validators = this.injector.get('validators');
}
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何使这些输入之一成为可选(即它可能存在也可能不存在)。我尝试过各种方法,例如添加“?” 并将该this.injector.get行换行为条件语句。我得到的只是一个“没有提供者...... ”错误。
假设parent在某些情况下输入可能不存在。我如何在生成的组件中解释这一点?
就像标题一样。Laravel 5.6中的默认API中间件列为Kernel.php:
protected $middlewareGroups = [
'api' => [
'throttle:60,1',
'bindings',
],
];
Run Code Online (Sandbox Code Playgroud)
我很感谢外行对功能的解释bindings,这在任何地方都找不到。
它使用SubstituteBindings具有handle方法的类:
public function handle($request, Closure $next)
{
$this->router->substituteBindings($route = $request->route());
$this->router->substituteImplicitBindings($route);
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
尽管我仍然不了解它的作用。
我已经阅读了一些有关此问题,但仍不清楚。哪个是正确的:
{"some_parameter": "true"}
Run Code Online (Sandbox Code Playgroud)
要么
{"some_parameter": true}
Run Code Online (Sandbox Code Playgroud)
我认为第二个是通过json发送布尔值的正确,正确的方法吗?但是第一个仍然是有效的json ...
这里的上下文是我正在构建一个API(供某些第三方应用程序使用),并且我想知道是否完全禁止第一种类型(拒绝错误)或像这样的字符串接受布尔数据是否合理,并且试图处理(转换)它们?
我正在寻找一些关于如何设置 Laravel mix 以查找特定阈值大小下的图像资源并将其在样式表中重新编码为 Base 64 字符串的指示。我可以使用 Webpack 来实现这一点url-loader,但我很难让配置在我的 Mix 配置中工作。我尝试过的:
const mix = require('laravel-mix');
mix.setPublicPath('public_html/');
mix.js('resources/uxmaps/js/app.js', 'uxmaps/js/app.js').version()
.webpackConfig({
module: {
rules: [
{
test: /\.(png|jpg|gif)$/i,
use: [
{
loader: 'url-loader',
options: {
limit: 8192,
outputPath: 'images'
},
},
],
}
]
}
})
.sass('resources/sass/app.scss', 'css/main.css')
Run Code Online (Sandbox Code Playgroud)
编译没有错误,但它根本不起作用;例如,我的 sass 文件中的背景图像background-image: url(/assets/logo.jpg);(3kb)在输出的 css 中保持原样。
其次,我还尝试url-loader根据混合文档将配置部分分离到一个单独的文件(导入的模块)中:https://laravel-mix.com/docs/5.0/extending-mix(请参阅“用法”部分)在底部)。结果相同:编译没有错误,但根本不起作用。
最后,我还尝试使用Post CSS 插件执行此操作,但在编译时它给了我与依赖项版本相关的错误(我认为这现在已经过时了)。
有任何关于为什么此代码无法正常工作的指示,或者任何其他方法可以使用 Laravel mix 将图像转换为内联 Base 64 吗?
谢谢
编辑 我发现我正在使用图像的绝对路径,因此 Mix 根据文档忽略它们。如果我更改为相对路径,则 …
我一直遇到这个问题。我需要能够将组件中各种元素的背景设置为动态线性渐变。(上下文正在创建一个网格背景,根据各种输入进行缩放和调整)。
我希望能够linear-gradient在函数中动态构建 CSS 背景属性,例如,这是我想要实现的简化版本:
createBackgroundString(){
return 'linear-gradient(' + this.angle + 'deg, ' + this.color1 + ', ' + this.color2 + ')';
}
Run Code Online (Sandbox Code Playgroud)
...然后将其粘贴到我的:style属性中,让 Vue 动态应用它:
v-bind:style="{ background: createBackgroundString() }"
Run Code Online (Sandbox Code Playgroud)
Vue 完全拒绝(忽略)这一点,大概是因为生成的字符串太复杂,无法适应属性模板,该模板需要一个简单的字符串,如“red”或“#FF000”等。
有什么方法/黑客/解决方法可以在 Vue 中实现此目的吗?目前我不得不求助于 jQuery,这远非理想。
angular ×2
laravel ×2
laravel-5 ×2
base64 ×1
boolean ×1
css ×1
foreign-keys ×1
json ×1
laravel-mix ×1
middleware ×1
php ×1
vue.js ×1
vuejs2 ×1
webpack ×1