Create method show () in Laravel

2

I am working on a library control system, when making an individual view of an element of the database I use the show method of my LibroController in the following way:

public function show($id)
{
    $libros = Libro::find($id);
    return view('libro.show', ['libro'=>$this->libro]);
} 

and a show.blade.php view like this:

@extends('layouts.admin')

@section('content') 

@include('alerts.request')

  {!!Form::model($libro,['route'=>  ['libro.show',$libro->id],'method'=>'POST','files'=> true])!!}

 <p class="info">AUTOR:&nbsp;&nbsp;{{$libro->autor}}</p>
 <p class="info">IDIOMA:&nbsp;&nbsp;{{$libro->idioma}}</p>
 <p class="info">PAGINAS:&nbsp;&nbsp;{{$libro->paginas}}</p>


{!!Form::close()!!}


@stop

As I understand it, using the {!!Form::model!!} would save me creating the route, but I still get the following error:

these are my routes

Route::get('/','[email protected]');
Route::get('contacto','[email protected]');
Route::get('reviews','[email protected]');
Route::get('admin','[email protected]');
Route::get('ver','[email protected]');

Route::get('password/email','Auth\[email protected]');
Route::post('password/email','Auth\[email protected]');
Route::get('password/reset/{token}','Auth\[email protected]');
Route::post('password/reset','Auth\[email protected]');

Route::resource('mail','MailController');

Route::resource('usuario','UsuarioController');
Route::resource('persona','PersonaController');
Route::resource('libro','LibroController');

Any contribution is welcome.

    
asked by Santiago Avila 04.02.2017 в 00:50
source

1 answer

2

The problem is because you are passing the wrong value to the view in your controller. So $ this- > books does not exist and will give you the error you report.

So your code should work if you do it this way.

public function show($id)
{
    $libros = Libro::find($id);
    return view('libro.show', ['libro'=>$libros]);
} 
    
answered by 28.03.2017 в 03:21