How do I resolve the "Call to undefined method Illuminate \ Database \ Query \"

2

In my blog I present all the articles in the beginning with a substr of what the post says, then I have a button to read more to see the article in another view and that's where my error comes from. It shows me the following error " Call to undefined method Illuminate \ Database \ Query \ Builder :: findBySlug () "

My route is as follows

Route::get('article/{slug}',[
    'uses' => '[email protected]',
    'as'   => 'article'
]);

My FrontController @ article

<?php

namespace Blog\Http\Controllers;

use Illuminate\Http\Request;

use Blog\Http\Requests;
use Blog\Articulo;
use Blog\User;
use Blog\Categoria;
use Blog\Http\Controllers\Controller;

class FrontController extends Controller{
    public function article($slug){

        $articul = Articulo::findBySlug($slug);
        return view('articulo',compact('articul'));
    }

}

My view article

<div class="row">
        <div class="col-md-8">
            <h1>Ultimas Noticias</h1>
                <article>
                    <h2>{{$articul->titulo}}</h2>
                    <div class="row">
                        <div class="col-md-6">
                            <span class="glyphicon glyphicon-folder-open" aria-hidden="true"></span> {{ $articul->categoria->categoria }}
                            <span class="glyphicon glyphicon-user" aria-hidden="true"></span> {{ $articul->user->name }}
                        </div><!--fin del col-md-6-->

                        <div class="col-md-6">
                            <span class="glyphicon glyphicon-calendar" aria-hidden="true"></span> {{ $articul->created_at }}
                        </div><!--fin del col-md-6-->

                    </div><!--fin del row dentro de col-md-8-->
                    <br>
                    <img src="img/{{$articul->path }}" alt="" class="img-responsive">
                    <br>
                    <p>{{ $articul->contenido }}</p>
                </article>
        </div> <!--fin del col-md-8-->

When I show my articles through the index if it looks good, but when I try to see an article in particular I loose that error.

Model Article

<?php

namespace Blog;

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Carbon\Carbon;
class Articulo extends Model{

    use Sluggable;

    /**
    * Return the sluggable configuration array for this model.
     *
     * @return array
     */
    public function sluggable(){
        return [
            'slug' => [
                'source' => 'titulo'
            ]
        ];
    }
     protected $table = 'articulos';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['titulo', 'contenido','slug','path','etiqueta','user_id','categoria_id'];

    public function setPathAttribute($path){
        if(! empty($path)){
            $name = Carbon::now()->second.$path->getClientOriginalName();
            $this->attributes['path'] = $name;
            \Storage::disk('local')->put($name, \File::get($path));
        }
    }



    public function categoria(){
        return $this->belongsTo('Blog\Categoria');
    }

    public function user(){
        return $this->belongsTo('Blog\User');
    }

    public function scopeTitulo($query, $titulo){//Funcion para hacer una busqueda 
        if(trim($titulo) != ''){ //Funcion trim para eliminar los espacios
            $query->where(\DB::raw("titulo"),"LIKE","%$titulo%");
        }


    }
}
    
asked by Luis Morales 03.10.2016 в 07:42
source

1 answer

1

In the most recent versions of Sluggable these methods are part of the helpers (of Sluggable) and you have to include them separately in your model:

<?php

namespace Blog;

use Illuminate\Database\Eloquent\Model;
use Cviebrock\EloquentSluggable\Sluggable;
use Cviebrock\EloquentSluggable\SluggableScopeHelpers;
use Carbon\Carbon;

class Articulo extends Model{

    use Sluggable, SluggableScopeHelpers;

    // ...

}
    
answered by 03.10.2016 / 17:57
source