dimanche 26 février 2017

error: undefined function in laravel even though function is defined in controller

I have the following lines of code in my laravel controller:

public function getTags() {
    $tags = DB::table('tags')->get();
    /* convert Object to array */
    $tagsArray = array();
    foreach($tags as $tag) {
        $tagsArray[$tag->tag] = $tag->tag; 
    }
    return $tagsArray = json_decode(json_encode($tagsArray) , TRUE);
}

public function index() {
    // $recentBlogPost = DB::table('Admin')->get();
    // Auth::logout();
    if (!(Auth::check())) {
        return Redirect::to('login');
    }       

    $tagsArray = getTags();
    return view('admin.index')->with('tags' , $tagsArray);
}

Now i get an error on the following line of my code:

$tagsArray = getTags();

I get the following error:

Call to undefined function App\Http\Controllers\getTags()

Now i have this function defined in the same controller where this function is being called, So why am i getting this error of undefined function ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire