Comments (8)
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.
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.
I'm using Laravel 7
from laravel-widgets.
The correct method is this.
{{ Widget::run('customMenu', [], $variable1, $variable2) }}
Could you check this,
@widget('customMenu',[], ['page' => 'company'])
from laravel-widgets.
Its works, @AlexThousand?
from laravel-widgets.
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.
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.
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)
- reloadtimeout not working HOT 2
- Can i use laravel-widgets in jquery drag and drop HOT 1
- JavaScript callback on async widget HOT 4
- Accessing config array of widget externally HOT 1
- Cache forever HOT 3
- Compatible for laravel 8 HOT 1
- laravel widget async error HOT 3
- Composer killed on composer require arrilot-widgets HOT 1
- Unable to access Auth::id() in asyncWidget HOT 3
- Can not pass variable to Widget (via Config Array) HOT 5
- How do using ajax for pagination HOT 1
- Pricing of spaces HOT 1
- asyncWidget with chart data not showing anything HOT 3
- parseFullWidgetNameFromString breaks namespace with caps and lower case characters HOT 1
- Issue Wrap same group with a class (PS: not each) HOT 1
- PHP 8.2 deprecation error HOT 1
- Delay loading of asyncWidget? HOT 1
- Can we rearrange folder and file structure HOT 1
- jQuery is undefined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-widgets.