I’m studying Laravel 6 and there is always a problem with the blade template.
The templates do not work: @csrf
, @error ("name")
$message
@enderror
, @method ("patch")
, although constructs like @foreach
, @forelse
and @if
work without problems.
Instead, I use {{csrf_field ()}}
, @foreach ($ errors-> all () as error) {$ error} @endforeach
respectively.
If @error("name") $message @enderror
throws an error: Undefined variable: message, then @csrf
and @method ("patch")
just output in HTML as plain text. Now there is a problem with @method ("patch"). I work on windows 7, open server I write everything according to the documentation, but I have to look for another way to write code. What could be the problem?
Here's the situation with @error ("name") {$ message}. Here is the controller.
<?php
namespace App \ Http \ Controllers;
use App \ Http \ Controllers \ Controller;
use Illuminate \ Http \ Request;
use Illuminate \ Support \ Facades \ DB;
class ServiceController extends Controller
{
public function index () {
$ var = 'create';
return view ('services.index', ['data' => $ var,]);
}
public function store (Request $ request) {
$ data = $ this-> validate ($ request, [
'name' => 'required'
]);
$ var = request ('name');
DB :: table ('services') -> insert (['name' => $ var]);
return redirect () -> back ();
}
}
Here is the template in services / index.blade.php. All templates are named correctly.
@extends ('html')
@section ('title', 'create')
@section ('content')
<h1> Create service </h1>
<form action = '/ service' method = 'post'>
<input type = 'text' name = 'name'>
{{csrf_field ()}}
<button> Add service </button>
</form>
@error ('name') {{$ message}} @enderror
@endsection