草庐IT

php - 循环 PHP 嵌套数组 - 将值提取到 Blade Views (Laravel)

我知道有很多关于这个主题的问题,但没有一个能完全解决这个问题(据我所知)。我在Laravel项目中有一个PHP数组(仅供引用,通过Guzzle响应返回)。PHP数组$users=array(2){["error"]=>bool(false)["spirits"]=>array(2){[0]=>array(2){["id"]=>string(1)"1"["name"]=>string(5)"Foo"}[1]=>array(2){["id"]=>string(1)"2"["name"]=>string(3)"Bar"}}}我只是想提取下面的“id”和“name”键,以便在View中使用,但

php - 使用碳对象的 Laravel 数据透视表额外日期时间字段格式(不是时间戳)

我的应用程序中有一个数据透视表('offer_usage_detail'),该表有4个字段,如下所示idintAutoIncrementuser_idintreferencetousertableoffer_idintreferencetooffertableuse_datedate-timeStoredatetimewhenuseruseoffer我需要以d-m-YH:i格式显示使用报价的用户列表以及日期和时间。所以我在报价模型中添加了以下代码publicfunctionuser(){return$this->belongsToMany('User','offer_usage_det

php - Laravel 不添加自定义 header

使用laravel,我试图将我自己的header添加到服务器的所有响应中。我在filters.php中有以下内容:App::after(function($request,$response){//securityrelated$response->headers->set('X-Frame-Options','deny');//Anticlickjacking$response->headers->set('X-XSS-Protection','1;mode=block');//Anticrosssitescripting(XSS)$response->headers->set('X

php - Blade::extend 函数中 $1 和 $2 的含义是什么

我在LaravelDocs中看到了这个例子:Blade::extend(function($view,$compiler){$pattern=$compiler->createMatcher('datetime');returnpreg_replace($pattern,'$1format(\'m/d/YH:i\');?>',$view);});但是我好像没看懂,有的时候网上的例子里有$3。我没有通过Google搜索找到正确的答案,感谢任何帮助。 最佳答案 这是一个字符串替换!它将变量(例如$1)替换为模式的匹配组!例如(伪代码):

php - 我如何查询laravel中的深度关系并按 child 过滤 parent ?

例如,如果一个类别有很多产品,这些产品有很多SKU,我如何获得所有具有价格大于10的SKU的产品?这将返回所有类别,但只附加了预期的skus,我只需要包含skus的类别。$category=newCategory();$category->with(array('products','products.skus'=>function($query){$query->where('price','>',10);}))->get(); 最佳答案 您正在寻找的是whereHas()。您也可以直接编写with(array('products

php - laravel 中的 API 版本控制 : routing depending on the "Accept" Header

因为我想在接受header时触发端点,所以我创建了一个中间件来识别哪个版本正在使用客户端://ApiVersionMiddlewarepublicfunctionhandle($request,Closure$next){$route=$request->route();$actions=$route->getAction();$actions['uses']=str_replace('{api}',$request->header('api-version'),$actions['uses']);$route->setAction($actions);return$next($req

php - Laravel 5 Schedular 与 Indatus 调度程序

我一直在研究IndatusDispatcher(https://github.com/Indatus/dispatcher),它看起来比Laravel5中内置的调度器灵活得多。例如使用Dispatcher我可以:...->daysOfTheMonth([1,15])让命令在每个月的1号和15号执行。据我所知,您不能使用Scheduler做到这一点:...->monthly(1,15)这行不通,因为该函数不接受任何参数。我是不是遗漏了什么或者Dispatcher好得多? 最佳答案 IndatusDispatcher与Laravel5不

php - Laravel 5 问题与 wherePivot

我正在使用Laravel5,但在让->wherePivot()处理多对多关系时遇到问题。当我dd()SQL时,看起来Eloquent正在使用`pose_state`在数据透视表中查找记录。`pose_id`为null`。我希望这是一个简单的错误,而不是错误。任何想法表示赞赏。数据库结构姿势idnametype状态idnamemachine_name姿态状态pose_idstate_idstatus模型姿势belongsToMany('App\State')->withPivot('status_id')->withTimestamps();}publicfunctionscopeWit

php - Laravel 5 验证唯一传递变量占位符

是否可以通过带有变量的额外where子句传递唯一验证方法?举个例子:在我的模型中,我有自己的验证规则。publicstatic$rules=array('amount'=>'required|numeric','user_id'=>'required|exists:users,id','cause_id'=>'required|exists:causes,id','circle_id'=>'required|unique:donations,circle_id,NULL,id,cause_id,:cause_id',);然后在我的Controller中运行:$input=array('

php - 在 Laravel 5 中间件中操作 JSON

我有一个发送到Laravel5应用程序的Ajax请求。但是在将JSON发送到Controller之前,我需要重新格式化/更改/...JSON。有没有办法在中间件中操作请求体(JSON)?isJson()){$json=json_decode($request->getContent(),TRUE);//manipulatethejsonandsetitagaintothetherequest$manipulatedRequest=....$request=$manipulatedRequest;}\Log::info($request);return$next($request);}}