laravel public static variable 1

laravel public static variable

class ContentController extends BaseController {

    public static $text = null;

    public static function getContent($description)
    {
        $content = Content::where('description', $description)->first();
        return static::$text = $content->text;
    }
}

Here is what the above code is Doing:
1. We’re creating a new class called ContentController.
2. We’re creating a static variable called $text.
3. We’re creating a static function called getContent.
4. We’re using the static keyword to access the $text variable.
5. We’re using the static keyword to access the getContent function.

The static keyword is used to access static variables and static functions.

Similar Posts