write a static function in a controller
public static function basics_form(){
echo '
<div class="container">
<form action = "create_article" method = "post">
<input type = "hidden" name = "_token" value = "'; echo csrf_token(); echo '">
<div class="form-group">
<label for="title">Title <span class="form-required" title="This field is required.">*</span></label>
<input required type="text" id="title" placeholder="Enter The Title" name="title" value="" size="50" maxlength="50" class="form-control required">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<textarea required type="text" id="edit-name" placeholder="55" name="content" value="" size="250" maxlength="250" class="form-control required"> </textarea>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</div>
';
}
and
how to call that static function in view blade
<?php use \App\Http\Controllers\AdminController; ?>
{{ AdminController::basics_form() }}
without creating an instance we can call directly that static function
class MathHelper {
public static function add($num1, $num2) {
return $num1 + $num2;
}
}
$result = MathHelper::add(5, 3); // Calling static method directly
In this example, the add()
method is defined as static in the MathHelper
class. You can call it directly using MathHelper::add(5, 3)
without creating an instance of the MathHelper
class.
how to call a static function in same class
class MathHelper {
public static function add($num1, $num2) {
return $num1 + $num2;
}
public function vamsi() {
$result = self::add(5, 3);
return $result;
}
}
ss
No comments:
Post a Comment