问题描述
<?PHP
namespace App\View\Components;
use Illuminate\View\Component;
class Admin.-newclubform extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{echo "demo";
return view('components.admin.-newclubform');
}
}
我使用 PHP artisan make:component Admin.Newclubform
命令在管理文件夹中创建组件。
视图部分工作但类被忽略。
PHP artisan make:component Admin.Newclubform 创建所有类和视图。类由工匠命令生成
解决方法
正如@shaedrich Admin 所提到的。Newclubform 不是一个有效的类名。
所以创建子文件夹运行命令如下
php artisan make:component Admin/NewClubForm
这将在里面创建文件
App\View\Components\Admin\NewClubForm
所以你的组件看起来像这样
<?php
namespace App\View\Components\Admin;
use Illuminate\View\Component;
class NewClubForm extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.admin.new-club-form');
}
}
然后你可以这样访问
<x-admin.newclubform></x-admin.newclubform>