Laravel Use of undefined constant in form

3.4k views Asked by At

Hello so I am a beginner in laravel and having some problems. I am not using Illuminate html for my forms because I want just plain html forms. I'm getting this Use of undefined constant id - assumed 'id' in my edit.blade.php. Here is my edit.blade.php:

<form action="/books/{{$book.id}}/update" method="POST">
    Title: <input type="text" name="title"> <br/>
   Author: <input type="text" name="author"> <br/>
    ISBN: <input type="text" name="isbn"> <br/>
        <input type="hidden" name="_method" value="PUT">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <input type="submit">
</form>

And in my controller:

public function getBook($id) {
    $book = Books::findOrFail($id);
    return view('books.edit', compact('book'));
}

Am I doing something wrong?

1

There are 1 answers

0
wobsoriano On

Ok so I fixed it by myself.

First thing is I changed the line {{$book.id}} to {{$book->id}}. Second is to edit .env with this values:

CACHE_DRIVER=array
SESSION_DRIVER=cookie
QUEUE_DRIVER=array

Then restart server php artisan serve.