php artisan make:component city
app / View / Components / city.php
namespace App\View\Components;
use Illuminate\View\Component;
class city extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public $city;
public function __construct()
{
$this->city = 'city';
}
/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\View\View|string
*/
public function render()
{
return view('components.city');
}
}
resources / views / components / city.blade.php
{{ $city }}
routes / web.php
Route::view('/component-city', 'component-example');
resources / views / component-examle.blade.php
<x-city/>
Laravel说:“未定义变量:城市”
我专门删除了“ app / View / Components / city.php”文件中的代码,但是显示了组件的内容。好像Laravel没有使用文件app / View / Components / city.php