jeudi 14 janvier 2016

Laravel 5.1: Calling a function from string

Currently I'm trying to call a function from a string.

This is the function, that I'll call later:

<?php
namespace App\Validation\Options;

class FacebookOptionValidation
{
    static public function validate()
    {
       echo: 'example';
       die();
    }
}

Here is my controller:

<?php
namespace App\Http\Controllers\Profile;

use App\Validation\Options;

class ProfileUserEditController extends Controller {

    public function updateUserOption()
    {
        $class = 'Options\FacebookOptionValidation';

        $class::validate();
    }
}

In this case Laravel shows an error: Class 'Options\FacebookOptionValidation' not found

But when I call my function like this, everything works fine:

use App\Validation\Options;

class ProfileUserEditController extends Controller {

    public function updateUserOption()
    {
        Options\FacebookOptionValidation::validate();
    }
}

As mentioned here, it's possible to call a class/function from a string. But in my case it's not possible - neither in the static or non-static variant.

Is that a 'laravel-thing'?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire