- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试查询我在 Laravel 中设置的模型。我想要做的就是在我的 categories
表中获取所有 categories
,这些 categories
具有给定的 App\Category
实例作为它们的 parent
。不幸的是,我的 hasMany 正在返回 Type error: Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, string given, called in/Users/infosec/kannopy/vendor/laravel/framework 中/src/Illuminate/Database/Query/Grammars/Grammar.php 第 122 行
这是我的 App\Category
模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $fillable = ['id', 'name'];
/**
* return the items in a category
*/
public function items(){
$this->hasMany('App\Item', 'category_id', 'id');
}
/**
* return the categories parent category
*/
public function parent_category(){
$this->belongsTo('App\Category', 'parent', 'id');
}
/**
* get a list of the child categories of any given category
*/
public function children(){
$this->hasMany('App\Category', 'parent', 'id');
}
}
这是我进行查询的 Controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Category;
class CategoryController extends Controller
{
/**
* return the children of a given category
*/
public function getChildren($id){
$parent = Category::find($id);
return $parent->children();
}
}
此外,这是category
表的数据库迁移:
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoriesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('parent')->unsigned()->nullable(); //this needs to be done before the foreign key constraint
$table->foreign('parent')->references('id')->on('categories')->onDelete('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('categories');
}
}
最后,这是完整的回溯(作为 html sinppet):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="robots" content="noindex,nofollow" />
<style>
/* Copyright (c) 2010, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.com/yui/license.html */
html{color:#000;background:#FFF;}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td{margin:0;padding:0;}table{border-collapse:collapse;border-spacing:0;}fieldset,img{border:0;}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:normal;}li{list-style:none;}caption,th{text-align:left;}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal;}q:before,q:after{content:'';}abbr,acronym{border:0;font-variant:normal;}sup{vertical-align:text-top;}sub{vertical-align:text-bottom;}input,textarea,select{font-family:inherit;font-size:inherit;font-weight:inherit;}input,textarea,select{*font-size:100%;}legend{color:#000;}
html { background: #eee; padding: 10px }
img { border: 0; }
#sf-resetcontent { width:970px; margin:0 auto; }
.sf-reset { font: 11px Verdana, Arial, sans-serif; color: #333 }
.sf-reset .clear { clear:both; height:0; font-size:0; line-height:0; }
.sf-reset .clear_fix:after { display:block; height:0; clear:both; visibility:hidden; }
.sf-reset .clear_fix { display:inline-block; }
.sf-reset * html .clear_fix { height:1%; }
.sf-reset .clear_fix { display:block; }
.sf-reset, .sf-reset .block { margin: auto }
.sf-reset abbr { border-bottom: 1px dotted #000; cursor: help; }
.sf-reset p { font-size:14px; line-height:20px; color:#868686; padding-bottom:20px }
.sf-reset strong { font-weight:bold; }
.sf-reset a { color:#6c6159; cursor: default; }
.sf-reset a img { border:none; }
.sf-reset a:hover { text-decoration:underline; }
.sf-reset em { font-style:italic; }
.sf-reset h1, .sf-reset h2 { font: 20px Georgia, "Times New Roman", Times, serif }
.sf-reset .exception_counter { background-color: #fff; color: #333; padding: 6px; float: left; margin-right: 10px; float: left; display: block; }
.sf-reset .exception_title { margin-left: 3em; margin-bottom: 0.7em; display: block; }
.sf-reset .exception_message { margin-left: 3em; display: block; }
.sf-reset .traces li { font-size:12px; padding: 2px 4px; list-style-type:decimal; margin-left:20px; }
.sf-reset .block { background-color:#FFFFFF; padding:10px 28px; margin-bottom:20px;
-webkit-border-bottom-right-radius: 16px;
-webkit-border-bottom-left-radius: 16px;
-moz-border-radius-bottomright: 16px;
-moz-border-radius-bottomleft: 16px;
border-bottom-right-radius: 16px;
border-bottom-left-radius: 16px;
border-bottom:1px solid #ccc;
border-right:1px solid #ccc;
border-left:1px solid #ccc;
word-wrap: break-word;
}
.sf-reset .block_exception { background-color:#ddd; color: #333; padding:20px;
-webkit-border-top-left-radius: 16px;
-webkit-border-top-right-radius: 16px;
-moz-border-radius-topleft: 16px;
-moz-border-radius-topright: 16px;
border-top-left-radius: 16px;
border-top-right-radius: 16px;
border-top:1px solid #ccc;
border-right:1px solid #ccc;
border-left:1px solid #ccc;
overflow: hidden;
word-wrap: break-word;
}
.sf-reset a { background:none; color:#868686; text-decoration:none; }
.sf-reset a:hover { background:none; color:#313131; text-decoration:underline; }
.sf-reset ol { padding: 10px 0; }
.sf-reset h1 { background-color:#FFFFFF; padding: 15px 28px; margin-bottom: 20px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
border: 1px solid #ccc;
}
</style>
</head>
<body>
<div id="sf-resetcontent" class="sf-reset">
<h1>Whoops, looks like something went wrong.</h1>
<h2 class="block_exception clear_fix">
<span class="exception_counter">1/1</span>
<span class="exception_title"><abbr title="Symfony\Component\Debug\Exception\FatalThrowableError">FatalThrowableError</abbr> in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Grammar.php line 107" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Grammar.php line 107</a>:</span>
<span class="exception_message">Type error: Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, string given, called in /Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 122</span>
</h2>
<div class="block">
<ol class="traces list_exception">
<li> in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Grammar.php line 107" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Grammar.php line 107</a></li>
<li>at <abbr title="Illuminate\Database\Grammar">Grammar</abbr>->columnize('1') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php line 122" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Grammar.php line 122</a></li>
<li>at <abbr title="Illuminate\Database\Query\Grammars\Grammar">Grammar</abbr>->compileColumns(<em>object</em>(<abbr title="Illuminate\Database\Query\Builder">Builder</abbr>), '1') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php line 76" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Grammar.php line 76</a></li>
<li>at <abbr title="Illuminate\Database\Query\Grammars\Grammar">Grammar</abbr>->compileComponents(<em>object</em>(<abbr title="Illuminate\Database\Query\Builder">Builder</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php line 52" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Grammar.php line 52</a></li>
<li>at <abbr title="Illuminate\Database\Query\Grammars\Grammar">Grammar</abbr>->compileSelect(<em>object</em>(<abbr title="Illuminate\Database\Query\Builder">Builder</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/MySqlGrammar.php line 38" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">MySqlGrammar.php line 38</a></li>
<li>at <abbr title="Illuminate\Database\Query\Grammars\MySqlGrammar">MySqlGrammar</abbr>->compileSelect(<em>object</em>(<abbr title="Illuminate\Database\Query\Builder">Builder</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php line 1578" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Builder.php line 1578</a></li>
<li>at <abbr title="Illuminate\Database\Query\Builder">Builder</abbr>->toSql() in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php line 1645" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Builder.php line 1645</a></li>
<li>at <abbr title="Illuminate\Database\Query\Builder">Builder</abbr>->runSelect() in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php line 1631" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Builder.php line 1631</a></li>
<li>at <abbr title="Illuminate\Database\Query\Builder">Builder</abbr>->get('1') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php line 613" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Builder.php line 613</a></li>
<li>at <abbr title="Illuminate\Database\Eloquent\Builder">Builder</abbr>->getModels('1') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php line 318" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Builder.php line 318</a></li>
<li>at <abbr title="Illuminate\Database\Eloquent\Builder">Builder</abbr>->get('1') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php line 288" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Builder.php line 288</a></li>
<li>at <abbr title="Illuminate\Database\Eloquent\Builder">Builder</abbr>->first('1') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php line 168" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Builder.php line 168</a></li>
<li>at <abbr title="Illuminate\Database\Eloquent\Builder">Builder</abbr>->find('id', '1')</li>
<li>at <abbr title=""></abbr>call_user_func_array(<em>array</em>(<em>object</em>(<abbr title="Illuminate\Database\Eloquent\Builder">Builder</abbr>), 'find'), <em>array</em>('id', '1')) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php line 3516" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Model.php line 3516</a></li>
<li>at <abbr title="Illuminate\Database\Eloquent\Model">Model</abbr>->__call('find', <em>array</em>('id', '1'))</li>
<li>at <abbr title=""></abbr>call_user_func_array(<em>array</em>(<em>object</em>(<abbr title="App\Category">Category</abbr>), 'find'), <em>array</em>('id', '1')) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php line 3530" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Model.php line 3530</a></li>
<li>at <abbr title="Illuminate\Database\Eloquent\Model">Model</abbr>::__callStatic('find', <em>array</em>('id', '1')) in <a title="/Users/infosec/myProject/app/Http/Controllers/CategoryController.php line 17" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">CategoryController.php line 17</a></li>
<li>at <abbr title="App\Http\Controllers\CategoryController">CategoryController</abbr>->getChildren('1')</li>
<li>at <abbr title=""></abbr>call_user_func_array(<em>array</em>(<em>object</em>(<abbr title="App\Http\Controllers\CategoryController">CategoryController</abbr>), 'getChildren'), <em>array</em>('id' => '1')) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Controller.php line 55" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Controller.php line 55</a></li>
<li>at <abbr title="Illuminate\Routing\Controller">Controller</abbr>->callAction('getChildren', <em>array</em>('id' => '1')) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php line 44" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">ControllerDispatcher.php line 44</a></li>
<li>at <abbr title="Illuminate\Routing\ControllerDispatcher">ControllerDispatcher</abbr>->dispatch(<em>object</em>(<abbr title="Illuminate\Routing\Route">Route</abbr>), <em>object</em>(<abbr title="App\Http\Controllers\CategoryController">CategoryController</abbr>), 'getChildren') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Route.php line 189" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Route.php line 189</a></li>
<li>at <abbr title="Illuminate\Routing\Route">Route</abbr>->runController() in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Route.php line 144" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Route.php line 144</a></li>
<li>at <abbr title="Illuminate\Routing\Route">Route</abbr>->run(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 642" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Router.php line 642</a></li>
<li>at <abbr title="Illuminate\Routing\Router">Router</abbr>->Illuminate\Routing\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php line 53" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 53</a></li>
<li>at <abbr title="Illuminate\Routing\Pipeline">Pipeline</abbr>->Illuminate\Routing\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php line 41" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">SubstituteBindings.php line 41</a></li>
<li>at <abbr title="Illuminate\Routing\Middleware\SubstituteBindings">SubstituteBindings</abbr>->handle(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>), <em>object</em>(<abbr title="Closure">Closure</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 137" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 137</a></li>
<li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->Illuminate\Pipeline\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php line 33" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 33</a></li>
<li>at <abbr title="Illuminate\Routing\Pipeline">Pipeline</abbr>->Illuminate\Routing\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php line 48" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">ThrottleRequests.php line 48</a></li>
<li>at <abbr title="Illuminate\Routing\Middleware\ThrottleRequests">ThrottleRequests</abbr>->handle(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>), <em>object</em>(<abbr title="Closure">Closure</abbr>), '60', '1') in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 137" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 137</a></li>
<li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->Illuminate\Pipeline\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php line 33" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 33</a></li>
<li>at <abbr title="Illuminate\Routing\Pipeline">Pipeline</abbr>->Illuminate\Routing\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 104" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 104</a></li>
<li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->then(<em>object</em>(<abbr title="Closure">Closure</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 644" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Router.php line 644</a></li>
<li>at <abbr title="Illuminate\Routing\Router">Router</abbr>->runRouteWithinStack(<em>object</em>(<abbr title="Illuminate\Routing\Route">Route</abbr>), <em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 618" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Router.php line 618</a></li>
<li>at <abbr title="Illuminate\Routing\Router">Router</abbr>->dispatchToRoute(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Router.php line 596" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Router.php line 596</a></li>
<li>at <abbr title="Illuminate\Routing\Router">Router</abbr>->dispatch(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php line 267" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Kernel.php line 267</a></li>
<li>at <abbr title="Illuminate\Foundation\Http\Kernel">Kernel</abbr>->Illuminate\Foundation\Http\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php line 53" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 53</a></li>
<li>at <abbr title="Illuminate\Routing\Pipeline">Pipeline</abbr>->Illuminate\Routing\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/barryvdh/laravel-debugbar/src/Middleware/Debugbar.php line 51" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Debugbar.php line 51</a></li>
<li>at <abbr title="Barryvdh\Debugbar\Middleware\Debugbar">Debugbar</abbr>->handle(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>), <em>object</em>(<abbr title="Closure">Closure</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 137" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 137</a></li>
<li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->Illuminate\Pipeline\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php line 33" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 33</a></li>
<li>at <abbr title="Illuminate\Routing\Pipeline">Pipeline</abbr>->Illuminate\Routing\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php line 46" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">CheckForMaintenanceMode.php line 46</a></li>
<li>at <abbr title="Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode">CheckForMaintenanceMode</abbr>->handle(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>), <em>object</em>(<abbr title="Closure">Closure</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 137" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 137</a></li>
<li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->Illuminate\Pipeline\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php line 33" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 33</a></li>
<li>at <abbr title="Illuminate\Routing\Pipeline">Pipeline</abbr>->Illuminate\Routing\{closure}(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php line 104" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Pipeline.php line 104</a></li>
<li>at <abbr title="Illuminate\Pipeline\Pipeline">Pipeline</abbr>->then(<em>object</em>(<abbr title="Closure">Closure</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php line 149" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Kernel.php line 149</a></li>
<li>at <abbr title="Illuminate\Foundation\Http\Kernel">Kernel</abbr>->sendRequestThroughRouter(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php line 116" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">Kernel.php line 116</a></li>
<li>at <abbr title="Illuminate\Foundation\Http\Kernel">Kernel</abbr>->handle(<em>object</em>(<abbr title="Illuminate\Http\Request">Request</abbr>)) in <a title="/Users/infosec/myProject/public/index.php line 53" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">index.php line 53</a></li>
<li>at <abbr title=""></abbr>require('/Users/infosec/myProject/public/index.php') in <a title="/Users/infosec/.composer/vendor/laravel/valet/server.php line 106" ondblclick="var f=this.innerHTML;this.innerHTML=this.title;this.title=f;">server.php line 106</a></li>
</ol>
</div>
</script>
</body>
</html>
最佳答案
你的 parents
函数不应该在 Category
类中,而应该在 Item
类中
分类类
public function parent_category(){
return $this->belongsTo('App\Category', 'parent', 'id');
}
public function children(){
return $this->hasMany('App\Category', 'parent', 'id');
}
你的 Controller 的功能应该是:
public function getChildren($id){
$parent = Category::where('id', $id)->with('children')->first();
return $parent->children;
}
或
public function getChildren($id){
return Category::where('parent', $id)->get();
}
第一个代码运行两个查询来查找父级然后找到它的子级,而第二个代码运行单个查询并直接通过父级的 ID 找到子级。
关于php - 查询 Eloquent hasMany 返回 columnize 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40558975/
我有三张 table 。表 A 有选项名称(即颜色、尺寸)。表 B 有选项值名称(即蓝色、红色、黑色等)。表C通过将选项名称id和选项名称值id放在一起来建立关系。 我的查询需要显示值和选项的名称,而
在mysql中,如何计算一行中的非空单元格?我只想计算某些列之间的单元格,比如第 3-10 列之间的单元格。不是所有的列...同样,仅在该行中。 最佳答案 如果你想这样做,只能在 sql 中使用名称而
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 7 年前。 Improve this ques
我正在为版本7.6进行Elasticsearch查询 我的查询是这样的: { "query": { "bool": { "should": [ {
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 7 年前。 Improve this ques
是否可以编写一个查询来检查任一子查询(而不是一个子查询)是否正确? SELECT * FROM employees e WHERE NOT EXISTS (
我找到了很多关于我的问题的答案,但问题没有解决 我有表格,有数据,例如: Data 1 Data 2 Data 3
以下查询返回错误: 查询: SELECT Id, FirstName, LastName, OwnerId, PersonEmail FROM Account WHERE lower(PersonEm
以下查询返回错误: 查询: SELECT Id, FirstName, LastName, OwnerId, PersonEmail FROM Account WHERE lower(PersonEm
我从 EditText 中获取了 String 值。以及提交查询的按钮。 String sql=editQuery.getText().toString();// SELECT * FROM empl
我有一个或多或少有效的查询(关于结果),但处理大约需要 45 秒。这对于在 GUI 中呈现数据来说肯定太长了。 所以我的需求是找到一个更快/更高效的查询(几毫秒左右会很好)我的数据表大约有 3000
这是我第一次使用 Stack Overflow,所以我希望我以正确的方式提出这个问题。 我有 2 个 SQL 查询,我正在尝试比较和识别缺失值,尽管我无法将 NULL 字段添加到第二个查询中以识别缺失
什么是动态 SQL 查询?何时需要使用动态 SQL 查询?我使用的是 SQL Server 2005。 最佳答案 这里有几篇文章: Introduction to Dynamic SQL Dynami
include "mysql.php"; $query= "SELECT ID,name,displayname,established,summary,searchlink,im
我有一个查询要“转换”为 mysql。这是查询: select top 5 * from (select id, firstName, lastName, sum(fileSize) as To
通过我的研究,我发现至少从 EF 4.1 开始,EF 查询上的 .ToString() 方法将返回要运行的 SQL。事实上,这对我来说非常有用,使用 Entity Framework 5 和 6。 但
我在构造查询来执行以下操作时遇到问题: 按activity_type_id过滤联系人,仅显示最近事件具有所需activity_type_id或为NULL(无事件)的联系人 表格结构如下: 一个联系人可
如何让我输入数据库的信息在输入数据 5 分钟后自行更新? 假设我有一张 table : +--+--+-----+ |id|ip|count| +--+--+-----+ |
我正在尝试搜索正好是 4 位数字的 ID,我知道我需要使用 LENGTH() 字符串函数,但找不到如何使用它的示例。我正在尝试以下(和其他变体)但它们不起作用。 SELECT max(car_id)
我有一个在 mysql 上运行良好的 sql 查询(查询 + 连接): select sum(pa.price) from user u , purchase pu , pack pa where (
我是一名优秀的程序员,十分优秀!