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('/','FrontController@index');
Route::get('contacto','FrontController@contacto');
Route::get('reviews','FrontController@reviews');
Route::get('admin','FrontController@admin');
Route::get('ver','FrontController@ver');

Route::get('password/email','Auth\PasswordController@getEmail');
Route::post('password/email','Auth\PasswordController@postEmail');
Route::get('password/reset/{token}','Auth\PasswordController@getReset');
Route::post('password/reset','Auth\PasswordController@postReset');

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