在以下情况下,我需要一些帮助。
我愿意saveMany根据输入值。让我举一个例子。
我正在尝试以下方法。
$data = [
'id' => 1,
'name' => 'example',
'number_of_slots' => 5,
'material' => 'Colo',
'equipment_status_code_id' => 1,
];
$platecontainer = PlateContainer::create($data);
foreach ($data as $key => $value) {
$platecontainer->containerSlots()->saveMany([
new ContainerSlot([
'plate_container_id' => $data['id'],
'slot' => $data['number_of_slots'],
'occuiped' => false,
])
]);
}
Run Code Online (Sandbox Code Playgroud)
直到$platecontainer一切正常为止。我想要的是PlateContainer使用data数组创建a时,我也想创建插槽,但这是基于number_of_slots
因此,例如number_of_slots在示例中5,我想将5记录以(降序)保存在ContainerSlot表中
所以containerlots表最终看起来像这样。
有没有办法使用eloquent模型检索所有非空的记录.
例如
我有关系设置
板模型
public function project()
{
return $this->hasOne('App\Models\Project');
}
Run Code Online (Sandbox Code Playgroud)
项目模型
public function plate()
{
return $this->belongsTo('App\Models\Plate');
}
Run Code Online (Sandbox Code Playgroud)
如何检索所有有价值的记录.
尝试这个 return $p = \App\Models\Plate::with('project')->get();
将返回一切,即使是那些拥有的人NULL.
我想要的只是plates附有项目的.我试过laravel文档,但找不到任何东西.many关系 也有同样的方法
我需要一些关于以下主题的帮助和建议.
我的嘘声有一个简单的Apache服务器设置,并有一个简单的PHP身份验证 设置.只要使用这样的面板验证用户.
他/她可以访问在其后面运行的所有应用程序.换句话说,这个面板用作"门",如果你在门上,那么你就可以访问(当然在Web服务器上运行了权限表).
问题
我使用Laravel 5构建的应用程序需要在门后运行,因此这意味着应用程序需要知道用户是谁.
使用$_SERVER['PHP_AUTH_USER'];我可以获取username当前登录的.
但是如果我想跟踪user's我的应用上的操作呢?我需要一些$this->user_id合适的东西吗?
所以我一想到用户通过'门'我就会获取username并创建一个用户,将其保存在我在Laravel后面运行的数据库中.
if(isset($_SERVER))
{
if ( array_key_exists( 'PHP_AUTH_USER', $_SERVER ) ) {
$agent = $_SERVER['PHP_AUTH_USER']; //Request::server('PHP_AUTH_USER')
}
$user = User::create([
'username' => $agent,
]);
}
Run Code Online (Sandbox Code Playgroud)
但这会让用户每次刷新页面!但是没有更进一步的最佳方法是什么?
我需要一个单独的提供者(我测试了上面的代码AppServiceProvider)吗?
$this->user_id保存后怎么办这样的username事呢?
注意:我知道Laravel有基本的auth开箱即用,但这不起作用,因为用户还没有在我的数据库中.我需要先像上面那样创建它们.
我现在正在处理以下问题一个星期。请耐心听我解释。
我想要实现的是,对于我们中的一些人来说,非常简单,但是对 WPF 来说是新手让事情变得困难。
上面的图像是通过转换(已经有)并随后将其导入到 Visual Studiosvg来呈现的xaml。这就是 xaml 的样子。
<Canvas x:Name="Main" Margin="158,-223,-148,233">
<Canvas.RenderTransform>
<MatrixTransform Matrix="1.25 0 0 -1.25 -197.1231 961.58875"/>
</Canvas.RenderTransform>
<Path xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="path139746" Fill="#FFD3BC5F" Canvas.Left="399.4" Canvas.Top="-172.6">
<Path.Data>
<PathGeometry Figures="m 66.611178 552.33853 c -4.36996 0.6305 -8.8334 0.97293 -13.3752 0.97293 -18.11465 0 -35.027 -5.21161 -49.34949 -14.18974 l 21.64732 -36.67733 c 8.2963 5.25686 18.12667 8.31294 28.67512 8.31294 2.7121 0 5.37755 -0.20365 7.98106 -0.59283 l 2.23539 -0.38916 c 4.72288 -0.91109 9.2226 -2.43913 13.41755 -4.49964 l 35.933612 77.65818 c -12.53504 …Run Code Online (Sandbox Code Playgroud) 我需要一些关于以下方面的建议.
我有2次迁移,就像这样.
Schema::create('plates', function (Blueprint $table) {
$table->increments('id');
$table->integer('serial_number');
$table->string('crc-code', 50);
$table->string('reason', 50)->nullable();
$table->softDeletes();
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
而另一个
Schema::create('documents', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 25)->unique();
$table->text('description')->nullable();
$table->longText('relative_path');
Run Code Online (Sandbox Code Playgroud)
我设置的多对多关系的数据透视表就像这样
Schema::create('document_plate', function (Blueprint $table) {
$table->integer('plate_id')->unsigned()->index();
$table->integer('document_id')->unsigned()->index();
$table->primary(['plate_id', 'document_id']);
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
采取某种行动时,我使用下面的代码将a附加plate到adocument
$plate = Plate::find(1);
$doc = Document::find(1);
if($plate && $doc) {
$plate->documents()->attach($doc->id);
}
Run Code Online (Sandbox Code Playgroud)
第一次,一切正常!将document_plate得到更新.ids再次执行相同操作时会发生错误.
SQLSTATE [23000]:完整性约束违规:1062重复条目'1-1'的关键'主要'(SQL:插入
document_plate(created_at,document_id,plate_id,updated_at)
现在的问题
有没有办法避免错误,只是用同样的方法更新表ids?
或者..我需要在前端设置某种验证,告诉用户(在提交之前)他/她选择id's已经在表中的相同内容. …
我有一个str像这样的有效载荷
payload = "{\"fqdn\":\"examplazdazdazazdzadza.com\",\"duration\":5,\"owner\":{\"city\":\"Paris\",\"given\":\"Alice\",\"family\":\"Doe\",\"zip\":\"75001\",\"country\":\"FR\",\"streetaddr\":\"5 rue neuve\",\"phone\":\"+33.123456789\",\"type\":0,\"email\":\"alice@example.org\"}}"
Run Code Online (Sandbox Code Playgroud)
这是来自 Gandi API的负载
我想让payload更动态一点,有一定的灵活性,所以我累了 dict
domain = 'example.com`
payload = {
'fqdn': domain,
'duration': 1,
'owner': {
"city": "Paris",
"given": "Alice",
"family": "Doe",
"zip": "75001",
"country": "FR",
"streetaddr": "5 rue neuve",
"phone": "+33.123456789",
"state": "FR-J",
"type": 0,
"email": "alice@example.org"
}
}
Run Code Online (Sandbox Code Playgroud)
在此之后,我需要恢复到原始日期类型(str),我这样做
payload = '\n'.join('\%s\: "\%s\"' % (k, v) for k, v in payload.items())
然而这会返回
错误的请求
.
任何想法如何正确完成这项工作?
laravel ×4
php ×4
animation ×1
apache ×1
c# ×1
dictionary ×1
python ×1
python-3.x ×1
wpf ×1
xaml ×1