【发布时间】:2022-01-25 03:00:51
【问题描述】:
一旦他们在我的 edit.blade.php 文件中编辑了一个库存项目,我正试图在浏览器上弹出一条消息。我已经连接了路由器、控制器和视图文件,因此我可以编辑一个库存项目并在浏览器上查看更改,但我的消息说您成功编辑了库存并没有显示。 这是我的 InventoryForm.php 组件表单:
<?php
namespace App\View\Components;
use App\Models\Inventory;
use Illuminate\View\Component;
class InventoryForm extends Component
{
/**
* @var Inventory|null
*/
public $inventory;
/**
* Successfully edited message
*
* @var string
*/
public $message;
/**
* @param Inventory|null $inventory
*
* @param string $message
*/
public function __construct(Inventory $inventory = null, string $message)
{
$this->inventory = $inventory;
$this->message = $message;
}
/**
* Get the view / contents that represent the component.
*
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render()
{
return view('components.inventory-form');
}
}
这是我的 edit.blade.php 文件:
@extends('layouts.app')
@section('title', 'Create Inventory')
@section('menu')
@section('content')
<h1><strong>Edit {{ $inventory->title }}</strong></h1>
<x-inventory-form :inventory=$inventory/>
@endsection
当我将鼠标悬停在构造函数旁边的 (Inventory $inventory = null) 上时,它还会显示“在需要之前提供了可选参数。”
当我尝试编辑库存项目时,我收到此错误:
类 App\View\Components\InventoryForm 中无法解析的依赖解析 [Parameter #0 [ string $message ]](视图:/var/www/html/resources/views/pages/inventories/edit.blade.php)
任何帮助都会很棒!谢谢!!
【问题讨论】:
标签: php laravel components