我通过Ajax将一个QueryString格式的文本发送到php脚本:
title=hello&custLength=200&custWidth=300
Run Code Online (Sandbox Code Playgroud)
我希望通过PHP中的结果将此文本转换为JSON对象:
{
"title" : "hello",
"custLength" : 200,
"custWidth" : 300
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点.有没有人有办法解决吗?
编辑: 事实上,我有一个表格中的三个元素,标题,custLength和custWidth名称,我试图通过serialize() jquery方法将这些元素作为一个参数发送到PHP脚本.
此代码用于将数据发送到php:
customizingOptions = $('#title,#custLength,#custWidth').serialize();
$.post('cardOperations',{action:'add','p_id':p_id,'quantity':quantity,'customizingOptions':customizingOptions},function(data){
if (data.success){
goBackBtn('show');
updateTopCard('new');
}
},'json');
Run Code Online (Sandbox Code Playgroud)
在PHP脚本中,我使用json_encode()将customizingOptions参数转换为json.
但结果不是我的预期,结果是一个简单的文字,如下所示:
"title=hello&custLength=200&custWidth=300"
Run Code Online (Sandbox Code Playgroud) 我正在使用Zizaco /委托 laravel包,现在我想在刀片模板中使用@role指令只显示一些项目,如下所示:
@role('developer,administrator')
<li><a href="/admin/permission">Permissions</a></li>
@endrole
Run Code Online (Sandbox Code Playgroud)
但这不起作用.可能吗 ?
要在laravel 5.1中创建自定义验证规则,我创建了一个CustomValidators在App/Validatiors目录中命名的类,如下所示:
namespace App\Validators;
use App\Classes\Utilities;
class CustomValidators extends \Illuminate\Validation\Validator
{
public function DateTime ($field , $value ,$param, $validator){
dd($value);
}
}
Run Code Online (Sandbox Code Playgroud)
在AppServiceProvider.php,我补充说:
Validator::extend('date_time', 'App\Validators\CustomValidators@DateTime');
Run Code Online (Sandbox Code Playgroud)
在store()控制器的功能我使用它像这样:
$rules = array (
'start_publish' => 'date_time',
);
Run Code Online (Sandbox Code Playgroud)
但是在运行App时出现此错误:
BindingResolutionException in Container.php line 824:
Unresolvable dependency resolving [Parameter #1 [ <required> array $data ]] in class Illuminate\Validation\Validator
Run Code Online (Sandbox Code Playgroud)
当我直接在所有东西中定义DateTime()函数时的诅咒AppServiceProvider.php是这样的:
Validator::extend('date_time', function ($field , $value ,$param, $validator){
dd($value);
});
Run Code Online (Sandbox Code Playgroud)
我正在使用PhpStorm 2016.1.1和数据库工具窗口来管理MySql数据库表。
有些表是无用的,我很少访问它们,并且占用了数据库工具窗口上的大量空间。
有什么方法可以隐藏 PhpStorm 数据库工具窗口中无用的表吗?
我想在 larvel 的动态频道上广播一个事件。
为了在特定频道上广播,我尝试了本教程,一切正常。
这是我的活动:
class ChatNewMessage implements ShouldBroadcast
{
use InteractsWithSockets, SerializesModels;
public $targetUsers;
public $message;
public function __construct ($message)
{
$this->targetUsers = $message->chat->users->pluck('user_id');
/*This is an array of user that are subscribed to a chat*/
$this->message = $message;
}
public function broadcastOn ()
{
$userChannels = [];
foreach ($this->targetUsers as $id) {
$userChannels[] = 'user-channel.' . $id;
}
return $userChannels;
}
}
Run Code Online (Sandbox Code Playgroud)
这是通过user_id=5获取用户发生的事件的 js 代码:
var socketURL = 'http://127.0.0.1:3000';
var socket = io(socketURL);
socket.on('user-channel.5:App\\Events\\ChatNewMessage', …Run Code Online (Sandbox Code Playgroud) 假设我有一个这样的集合:
Collection {#447
#items: array:3 [
0 => array:6 [
"pos" => "0"
"col" => "1"
"row" => "1"
"size_x" => "2"
"size_y" => "1"
"cat_id" => "1"
]
1 => array:6 [
"pos" => "0"
"col" => "3"
"row" => "1"
"size_x" => "1"
"size_y" => "1"
"cat_id" => "11"
]
2 => array:6 [
"pos" => "0"
"col" => "1"
"row" => "2"
"size_x" => "2"
"size_y" => "1"
"cat_id" => "10"
]
]
}
Run Code Online (Sandbox Code Playgroud)
现在我想要一个这样的数组,只获取cat_id索引. …