Jon Tan
Jon Tan

Reputation: 1551

’Call to a member function make() on null‘ When installing Eloquence

I'm trying to install Eloquence on my Laravel project.

Eloquence Installation

I'm following the installation, and I've done the following:

  1. Require the package in your composer.json
  2. Add Eloquence trait to the model
  3. Add Sofa\Eloquence\ServiceProvider to the config/app.php providers array

Problem: Post::search('jarek sofa')->get(); results in

FatalThrowableError in Builder.php line 77:
Call to a member function make() on null

Here is my code

Possible reasons:

  1. The Eloquence service provider wasn't registered properly
  2. Maybe something to do with composer

Thanks in advance

Upvotes: 0

Views: 2034

Answers (4)

Matthew Brierley
Matthew Brierley

Reputation: 1

Sorry to bump an old topic, but I have a different solution to anyone who might find themselves here: you cannot have a scope called 'search'.

I just had the exact same exception and couldn't work out why, although I figured it was a problem with me trying to call a scope dynamically through call_user_func_array. Thanks to this question having the exact same scope name, I figured it might be that and it was. There's probably many other 'reserved' names I don't know about, but as soon as I changed it to 'searchName' all is well.

Upvotes: 0

Parameshwar
Parameshwar

Reputation: 966

I was having same issue resolved it as following added dependencies to the composer "require": { "sofa/eloquence": "~5.3", // for Laravel 5.3.*

    // OR
    "sofa/eloquence": "~5.2", // for Laravel 5.2.*

    // OR
    "sofa/eloquence": "~5.1", // for Laravel 5.1.*

    // OR
    "sofa/eloquence": "~0.4", // for Laravel 5.0.*
    ...
},

then added the class in config/app 'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    .....
    Illuminate\View\ViewServiceProvider::class,

    /*
     * Package Service Providers...
     */
    Laravel\Tinker\TinkerServiceProvider::class,

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,

    Sofa\Eloquence\ServiceProvider::class,
],

finally did the composer update

Upvotes: 0

Jon Tan
Jon Tan

Reputation: 1551

Finally got it to work!

Solution: Add \Sofa\Eloquence\Builder::setParserFactory(new \Sofa\Eloquence\Searchable\ParserFactory);

in the AppServiceProvider boot method like this:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        \Sofa\Eloquence\Builder::setParserFactory(new \Sofa\Eloquence\Searchable\ParserFactory);
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

Upvotes: 1

Domagoj Šimić
Domagoj Šimić

Reputation: 26

Have you tried to run composer update command in console?

Upvotes: 0

Related Questions