I am currently trying to call a function from a string.
This is the function that I will name 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:
\ FacebookOptionValidation 'class parameters 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 , you can call a class / function from a string. But in my case this is impossible - neither in the static, nor in the unsteady version.
Is this a "laravel-thing"?
source
share