Q:

Laravel controller doesn´t process my view parameters

Guys I really need your help.
I have this controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Book;

class BookController extends Controller
{
    public function index()
    {
        $books = Book::orderBy('id', 'DESC')->paginate(5);
        return view('index', compact('books'));
    }

    public function create()
    {
        return view('add');
    }

    public function store(Request $request)
    {
        $this->validate($request, ['titulo' => 'required', 'npaginas' => 'required', 'edicion' => 'required', 'autor' => 'required', 'resumen'=>'required', 'precio'=>'required']);
        Book::create($request->all());
        return redirect()->route('index');
    }
    public function edit($id){

        return view('edit');
    }
    public function update(Request $request, $id)
    {
        $this->validate($request, ['titulo' => 'required', 'npaginas' => 'required', 'edicion' => 'required', 'autor' => 'required', 'resumen'=>'required', 'precio'=>'required']);
        book::find($id)->update($request->all());
        return redirect()->route('book.index');
    }

    public function destroy($id)
    {
        Book::find($id)->delete();
        return redirect()->route('index');
    }    
}

I have a view sending a id from a book to the edit and destroy functions. However I am only receiving a `404 error.
This is the view:
@if($books->count())
        @foreach($books as $book)
            <tr>
                <td>{{$book->titulo}}</td>
                <td>{{$book->npaginas}}</td>
                <td>{{$book->edicion}}</td>
                <td>{{$book->autor}}</td>
                <td>{{$book->resumen}}</td>
                <td>${{$book->precio}}</td>
                <td><a class="btn btn-primary btn-xs margen-boton"
                       href="{{ action('BookController@edit', $book->id) }}"><span
                            class="fas fa-pencil-alt"></span></a>
                </td>

                <td>
                    <form action="{{ action('BookController@destroy', $book->id )}}"
                          method="post">
                        {{csrf_field()}}
                        <input name="_method" type="hidden" value="DELETE">
                        <button class="btn btn-danger btn-xs margen-boton2" type="submit"><span
                                class="fas fa-trash-alt"></span></button>
                    </form>
                </td>
            </tr>
        @endforeach
    @else
        <tr>
            <td colspan="8" class="text-center"><p>Sin libros en el inventario</p></td>
        </tr>
    @endif

The truth is I´m changing the book variable name but it doesn´t do anything.
I try changing the controller name into the view cause I thought there was the problem. but that doesn´t work. I don´t really know what to do.
If you can help me, that would be awesome

A:

In simple example follow these steps
In your web.php file use this
Route::get("/edit/{id}", ["as" => "books.edit", "uses" => "BookController@edit"]);

After that here in BookController code should be like this
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Book;

class BookController extends Controller
{
    public function index()
    {
        ...
    }

    public function create()
    {
        ...
    }

    public function store(Request $request)
    {
        ....
    }
    public function edit($id){

        return view('edit', [
                'id' => $id
            ]);
    }

}

And in your index.blade.php file you need to create link like this
<a class="btn btn-primary btn-xs margen-boton"
    href="{{ route('books.edit', ['id' => $book->id]) }}">

    <span class="fas fa-pencil-alt"></span>
</a>

That will work exactly what you want.

