Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

a2v86's avatar
Level 1

Laravel 9: get_ip not displaying correctly :(

Greetings everyone,

Why is that my view.blade page instead of displaying the ip adress it displays text: menu_controller ? in my view blade i call the controller function with this code: {{ menu_controller::class, 'get_ip'}}

In my menu_controller i got this code in function: public function get_ip(Request $request) { $clientIP = $request->ip(); dd($clientIP); return 'dd'; }

Can anyone drive me through this logical error i made please ?

Thx !

0 likes
6 replies
tykus's avatar

This...

{{ menu_controller::class, 'get_ip'}}

... is not how Controllers are used. You are seeing menu_controller because that is the result of menu_controller::class.

Whatever Controller action is returning the view should pass the data needed by that view template.

1 like
a2v86's avatar
Level 1

@tykus in my controller i defined this function:

public function get_ip(Request $request)
{
    $clientIP = $request->ip();
    dd($clientIP);
    return 'dd';
}

isnt suppose to return me that variable ?

tykus's avatar

@a2v86 not if you try to call the function like this:

{{ menu_controller::class, 'get_ip'}}

Even if that code did work; a controller action is intended to handle a Request, and return a Response; not to arbitrarily fetch some data like this. Why do you not get the data in whatever Controller action you return the view?

1 like
a2v86's avatar
Level 1

@tykus something like this ?

public function get_ip(Request $request) { $clientIP = $request->ip(); dd($clientIP); return view("ip_adress", ["ip"=>$dd]); }

tykus's avatar
tykus
Best Answer
Level 104

@a2v86 no.

You're not understanding me. Why don't you just do this in the existing view, and forget the get_ip controller action completely!

{{ request()->ip() }}
1 like

Please or to participate in this conversation.