samedi 1 mai 2021

Call to undefined function App\Http\Controllers\Auth\get_option() in laravel 8

I'm trying to convert an Laravel 5.7 project to 8, still debugging but I can't fix that spesific issue.

When I run that project I get "Call to undefined function App\Http\Controllers\get_option()" error.

I tried:

  • Change helpers.php location Providers to Controllers
  • Remove if clause in helpers.php file
  • Add "use App\Providers\helpers;" in Mainpage controller
  • Check Laravel 8 upgrading guide (https://laravel.com/docs/8.x/upgrade)

This is a source of error in App\Http\Controllers\MainpageController:

...
        $products_recommendations = Product::select('product.*')

            ->join('product_details', 'product_details.product_id', 'product.id')

            ->where('product_details.show_recommendations', 1)

            ->orderBy('update_date', 'desc')

            ->take(get_option('mainpage_list_product_count'))->get();
...

This is app/Providers/helpers.php file, it has get_option() function:

<?php
use App\Models\Option;
use Illuminate\Support\Facades\Cache;

if (! function_exists('get_option')) {
    function get_option($key) {
        //$allOptions = Cache::rememberForever('allOptions', function() {
        $minute = 60;
        $allOptions = Cache::remember('allOptions', $minute, function() {
            return Option::all();
        });
        
        return $allOptions->where('key', $key)->first()->variable;
    }
}

How can I fix that?

Note: I translated variable and function names into English for asking here.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire