FatalErrorException in Book.php line 12: syntax error, unexpected 'public' (T_PUBLIC)

0

Good morning. I am currently in Laravel making an application for the management of a library and when entering the model a method to upload a file I get this error:

  

FatalErrorException in Libro.php line 12: syntax error, unexpected   'public' (T_PUBLIC) in Libro.php line 12

Here is my model and I do not see any syntax error:

<?php namespace Biblioteca;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Libro extends Model
{
protected $table = "libros";
protected $fillable = ['titulo','path', 'idioma','paginas','tipo','categoria', 'fecha_lanzamiento', 'descripcion','enlace','categoria_id'];
}

public function setPathAttribute($path)
{
    if(! empty($path)){

        $titulo = Carbon::now()->second.$path->getClientOriginalName();
        $this->attributes['path'] = $titulo;
        \Storage::disk('local')->put($titulo, \File::get($path));
    }
}

If you need to see the controller and the input method, I'll pass it.

    
asked by Santiago Avila 09.01.2017 в 10:45
source

1 answer

3

You need the functions to be inside some class. Your code should be:

<?php namespace Biblioteca;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;

class Libro extends Model
{
    protected $table = "libros";
    protected $fillable = ['titulo','path','idioma',
                          'paginas','tipo','categoria', 
                          'fecha_lanzamiento', 'descripcion',
                          'enlace','categoria_id'];

    public function setPathAttribute($path)
    {
        if(! empty($path)){

            $titulo = Carbon::now()->second.$path->getClientOriginalName();
            $this->attributes['path'] = $titulo;
            \Storage::disk('local')->put($titulo, \File::get($path));
        }
    }
}
    
answered by 09.01.2017 / 11:18
source