In Laravel, you can call a static method of a class directly from a route. Here is an example of how to do this:
Create a static method in a class. For example, create a class Example
with a static method hello()
:
class Example {
public static function hello() {
return 'Hello from Example class!';
}
}
In your routes/web.php
file, define a route that calls the static method:
Route::get('example', function () {
return Example::hello();
});
Now, when you visit http://your-app.test/example
in your browser, you will see the message “Hello from Example class!” displayed.
Note: Replace your-app.test
with the actual URL of your Laravel application.