Laravel刚起步,并且正在尝试为我的应用创建树状类别结构。这是我以前使用过的代码,但仍然无法实现我想要的代码。我的控制器:
public function index()
{
$categories = Category::with('children')->get();
return view('backend.categories.index')->with('categories', $categories);
}
Run Code Online (Sandbox Code Playgroud)
我的类别模型:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model
{
protected $guarded = ['id'];
public function parent()
{
return $this->belongsTo('App\Category', 'parent_id');
}
public function children()
{
return $this->hasMany('App\Category', 'parent_id');
}
}
Run Code Online (Sandbox Code Playgroud)
我的看法:
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Slug</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($categories as $category)
{{--@foreach ($category->children as $children)--}}
<tr>
<td>{{ $category->name }}</td>
<td>{{ $category->description }}</td>
<td>{{ $category->slug }}</td>
<td><a class="edit" href="{!! action('Admin\CategoriesController@edit', …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建我的应用程序,使我的所有模型都在一个专用目录中(在我的案例中分类).我用Laravel app目录创建了目录,并将其添加到我的composer.json文件中.下面是我的composer.json文件的结构:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Classified\\": "app/",
"Classified\\": "app/Classified"
}
},
Run Code Online (Sandbox Code Playgroud)
然后我在终端中运行composer dump-autoload,但我一直得到"Key Classified \在第29行的./composer.json中重复",当我尝试在浏览器中查看我的应用时,我得到:
致命错误:/home/vagrant/Workspace/codulabproducts/classified/vendor/laravel/framework/src/Illuminate/Container/Container.php上的未捕获异常'ReflectionException',消息'Class App\Http\Kernel is not exists' 736.
我的composer.json文件中的第29行是
"Classified\\": "app/Classified"
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题,因为我已经在我的其他项目中执行了这些步骤,一切顺利.
我开始学习如何使用 ionic 框架构建移动应用程序。
我确实看到有人使用 ionic build,而其他人使用cordova build。
我想知道两者之间的区别以及何时使用它们。
遵循NativeScript Groceries Typescript Angular教程,我在第3章遇到了以下错误.
EXCEPTION: Error in ./AppComponent class AppComponent_Host - inline template:0:0
ORIGINAL EXCEPTION: No provider for Http!
ORIGINAL STACKTRACE:
Error: DI Exception
at NoProviderError.BaseException [as constructor] (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/facade/exceptions.js:27:23)
at NoProviderError.AbstractProviderError [as constructor] (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_exceptions.js:43:16)
at new NoProviderError (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_exceptions.js:80:16)
at ReflectiveInjector_._throwOrNull (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_injector.js:786:19)
at ReflectiveInjector_._getByKeyDefault (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_injector.js:814:25)
at ReflectiveInjector_._getByKey (/data/data/org.nativescript.groce
Run Code Online (Sandbox Code Playgroud)
我在教程中来回走动,看看我是否错过了什么,但似乎我努力地遵循每一个步骤.
我该如何解决这个问题.