Comments (5)
I may have some more info on this @arrilot , check below example please and hope it helps.
(pls do not mind the stupidity in the example, it is just there to explain the output)
namespace App\Widgets;
use App\Contracts\Widget;
use App\Repositories\NewsRepository;
class LatestNews extends Widget
{
protected $config = ['count' => 5];
public function run()
{
$newsRepo = app(NewsRepository::class);
return view('widgets.latest_news', [
'config' => $this->config,
'news' => $newsRepo->recent($this->config['count']),
]);
}
}
Works just fine and config/count gets updated. However something like below makes config array changes impossible with widget calls.
namespace App\Widgets;
use App\Contracts\Widget;
use App\Repositories\NewsRepository;
use Illuminate\Support\Facades\Auth;
class LatestNews extends Widget
{
protected $config = ['count' => 5];
public function GetUser() {
$user = Auth::user();
return isset($user) ? $user->name_private : 'Dear Visitor';
}
public function run() {
$newsRepo = app(NewsRepository::class);
$user = $this->GetUser();
return view('widgets.latest_news', [
'config' => $this->config,
'user' => $user,
'news' => $newsRepo->recent($this->config['count']),
]);
}
}
So in simple terms, if I define anything more than public function run()
in widget controller and use them, config array remains unchanged by widget calls and always the defaults are being returned.
If I move all the additional functions inside run()
, config array starts acting normal.
from laravel-widgets.
Unfortunately I don't see any possible reasons why such behavior can happen.
I also cannot reproduce the issue on a fresh Laravel install.
You can try to reproduce it yourself and upload to a public github repo.
Wild guess: maybe you actually run your app on Laravel Octane instead of Apache.
from laravel-widgets.
I also noticed that you used your own widget class in extends Widget
Please make sure that you do not do any bad stuff there.
If you override AbstractWidget
constructor you should call parent::__construct($config)
in the end of the new __construct
from laravel-widgets.
Thanks for the reply, the main app is not using Laravel Octane and this is the Widget class we have in the app.
namespace App\Contracts;
use Arrilot\Widgets\AbstractWidget;
abstract class Widget extends AbstractWidget
{
public $cacheTime = 0;
public function view(string $template, array $vars = [])
{
return view($template, $vars);
}
}
Will try using AbstractWidget
to see if the Widget
class is causing this behavior.
from laravel-widgets.
It was the __construct
, thanks for pointing me out to the right direction... When I was defining additional functions, I was always using construct :)
public function __construct(
AirportRepository $airportRepo,
array $config = []
) {
$this->airportRepo = $airportRepo;
parent::__construct($config);
}
Closing this now, thanks again for your time and replies.
from laravel-widgets.
Related Issues (20)
- Passing variables to widget HOT 8
- 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
- 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.