koza95's avatar

Laravel correct view import

I am learning Laravel and I am a bit confused. PHPStorm offers me several view import options:

View
Illuminate\View\View
Illuminate\Contracts\View\View

which one should I choose?

I have tried using

use Illuminate\View\View;

also, several controllers are using

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;

They all seem to work in the same manner, which one is the correct way to import view class? I don't want to use View Facade. Thanks in advance for any help

0 likes
9 replies
koza95's avatar

As far as I understand I cant use compact('variable1', 'variable2') when using Facades

koza95's avatar

get to know which import should I use when using return view('foo', compact('bar'));

jlrdw's avatar

compact will still work, it's a straight php function. I use the view facade and still use compact to send data to the view.

Unless your use case is very different.

3 likes
koza95's avatar

I get this when trying to use compact with View Facade: Return value is expected to be '\Illuminate\Support\Facades\View', '\Illuminate\Contracts\View\View' returned so I assume use Illuminate\Contracts\View\View is the correct import, am I right?

jlrdw's avatar
return view('foo', compact("bar"));
3 likes

Please or to participate in this conversation.