Coder Social home page Coder Social logo

Comments (8)

gunmanix avatar gunmanix commented on July 26, 2024 1

It does not work with Laravel 7, i got the following exception:

@widget('recentNews', [], 'test')
Facade\Ignition\Exceptions\ViewException Unable to resolve dependency [Parameter #0 [ <required> $name ]] in class App\Widgets\RecentNews

But it's possible to passing the variables over the config array.

from laravel-widgets.

sebastienheyd avatar sebastienheyd commented on July 26, 2024 1

Hi!

I just send a PR to fix this issue by dynamically assigning the values to an associative array that will be used when calling the run method.

from laravel-widgets.

AlexThousand avatar AlexThousand commented on July 26, 2024

I'm using Laravel 7

from laravel-widgets.

fabdelgado avatar fabdelgado commented on July 26, 2024

Hi @AlexThousand

The correct method is this.
{{ Widget::run('customMenu', [], $variable1, $variable2) }}

Could you check this,
@widget('customMenu',[], ['page' => 'company'])

from laravel-widgets.

fabdelgado avatar fabdelgado commented on July 26, 2024

Its works, @AlexThousand?

from laravel-widgets.

nileshd avatar nileshd commented on July 26, 2024

Getting same error as @gunmanix , when I try to pass variables to the widget in Laravel 7..

@widget('DisplayValues', [], $properties)

Unable to resolve dependency [Parameter #0 [ $properties ]] in class App\Widgets\DisplayValues

Only config variables work in laravel7..

from laravel-widgets.

codemis avatar codemis commented on July 26, 2024

Current Solution

I found a solution, but I am not sure if it is the way you intended to use these arguments. If I call the widget with:

@widget('recentNews.recentNews', [], 'Afganisthan')

You can access the parameter in the run method like this:

public function run()
    {
        $country = func_get_arg(0);
        return view('widgets.recent_news.recent_news', [
            'country' => $country,
        ]);
    }

Was this the intended behavior? If so, then the README should be updated to reflect it.

The Problem

The README states:

@widget('recentNews', ['count' => 10], 'date', 'asc')
...
public function run($sortBy, $sortOrder) { }
...

If this is the intended behavior, then this may help with discovering the problem.

When the parameters are sent to the LaravelApplicationWrapper::call() method, they look like this:

Array ( [0] => date [1] => sortOrder )

It then calls the Container::call() method for Laravel, and eventually tries to find the dependency in BoundMethod::addDependencyForCallParameter() method. Since the array does not have a key with the name 'sortBy' or 'sortOrder', it is unable to match up the dependency with your widget run method. So it throws the error in line 180.

One possible fix is to use an array instead:

@widget('recentNews', ['count' => 10], ['sortBy' => 'date', 'sortOrder' => 'asc'])
...
public function run($sortBy, $sortOrder) { }
... 

However, I haven't found a way to implement this. In this situation, for some reason the array gets wrapped into an array, like this:

Array ( [0] => Array ( [sortBy] => date [sortOrder] => asc ) ) 

Which also cannot match up to the dependency. When I change the call method to this, it works:

return $this->app->call($method, $params[0]);

I hope this helps!

from laravel-widgets.

arrilot avatar arrilot commented on July 26, 2024

Unfortunately, Laravel has changed the behavior of method injection, so variables cannot be passed directly to run method in n Laravel >=7.

Please configure widgets using config array. Documentation is updated

from laravel-widgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.