Laravel 10和Livewire V3-语法错误,变量上的意外标识符“Name”,应为“)”

iqxoj9l9  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(88)

当我尝试访问我的模型的create路由时,我总是得到一个syntax error, unexpected identifier "Name", expecting ")"错误。语法是正确的,所有其他路由和视图都使用相同的变量。我已经注解掉了lang的所有__()刀片函数,并注解掉了错误块,视图工作正常。如果这个模型的所有其他视图的行为都是一样的,那么这是有意义的,但是我只在这个视图上得到这个错误的事实是奇怪的。我刚刚将我的项目从9升级到Laravel 10,从2升级到Livewire 3。

create.php

<?php

namespace App\Livewire\Fcrop;

use App\Models\Farm;
use App\Models\Fcrop;
use Livewire\Component;

class Create extends Component
{
    public $farm, $name, $type, $area;

    public function mount(Farm $farm)
    {
        $this->farm = $farm;
    }

    protected $messages = [
        'name' => 'Name is required.'
    ];

    public function createCropType()
    {
        //dd($this->farm->id);
        $this->validate([
            'name' => 'required|min:5',
            'area' => 'integer'
        ]);

        Fcrop::create([
            'farm_id' => $this->farm->id,
            'name' => $this->name,
            'type' => $this->type,
            'area' => $this->area,
        ]);

        return redirect()->route('farm.edit', $this->farm->id);
    }

    public function render()
    {
        return view('livewire.fcrop.create');
    }
}

create.blade.php

...
<form wire:submit="createCropType" method="POST" class="space-y-8 divide-y divide-gray-200">
    <div class="space-y-8 sm:space-y-5">
        <div class="pt-8 space-y-6 sm:pt-10 sm:space-y-5">
            <div class="space-y-6 sm:space-y-5">
                <div class="sm:grid sm:grid-cols-3 sm:gap-4 sm:items-start">
                    <label for="name" class="block text-sm font-medium text-gray-700">
                        {{ __('Name') }}
                    </label>
                    <div class="mt-1 sm:mt-0 sm:col-span-2">
                        <input wire:model.live="name" type="text" name="name" id="name">
                        @error('name')<span
                            class="mt-2 text-sm text-red-600">{{ $message }}</span>
                        @enderror
                    </div>
                </div>
...

截图

csbfibhn

csbfibhn1#

你错过了双quoute在年底类线以上

<label for="name" class="block text-sm font-medium text-gray-700">
{{ __('Name') }}
</label>

相关问题