Comments (5)
I'm not sure I would call it a bug but that could be improved. I'm confused by the syntax you show though since it's not blade or PHP.
from presenter.
Sorry I did not make myself clear enough cause Twig is an all time classic:
The syntax is Twig https://twig.symfony.com/, using https://github.com/rcrowe/TwigBridge, which Readme states that supports "can" as a function (though I am not using that) and found no issue regards "can" checking.
The following is pseudocode:
Do not work:
if myuser.can('update', mymodel)
do whatever...
endif
can('update', mymodel)
do whatever...
endcan
Do work after exposing protected object:
if myuser.can('update', mymodel.object)
do whatever...
endif
can('update', mymodel.object)
do whatever...
endcan
Haven't checked with Blade but my bet is it will not work either.
IMHO: decorating the model disables the container ability to resolve dependencies to be injected. I am not a dependency expert.
from presenter.
Laravel maps models to policies. So that is what is failing saying it doesn't find a policy so it will just return false. I think we can simply add can
to the presenter instance that retries on the object directly. And also add any other permission based methods.
from presenter.
Are you saying if I add a can() method to my presenter make this work?
https://laravel.com/docs/10.x/authorization#via-the-user-model
Something like this?
public function can($action)
{
return \Auth::user()->can($action, $this->object);
}
Then in my views:
myobject.can('update')
Though it may work, it looks wrong cause it shoud be read as myobject.canbe('updated')
I don't think you mean that :D
from presenter.
public function can($abilities, $arguments = [])
{
if (method_exists($this->object, 'can')) {
return $this->object->can($abilities, $arguments);
}
}
This is a quick and dirty way to do it. I would do it similar I think but checking the interface instead of method and maybe implement the interface in the presenter.
https://github.com/laravel/framework/blob/10.x/src/Illuminate/Contracts/Auth/Access/Authorizable.php
If it still doesn't work then you can implement that interface as well since there could be checks for it somewhere.
from presenter.
Related Issues (20)
- Factory not found HOT 1
- Issue with a presenter using Form::model. HOT 2
- How to use "Extending the Decorator" HOT 1
- Facades in Presenter HOT 2
- Q: Presenting on Objects from third-party Packages HOT 4
- I cant create a method to the field "Data_Nasc" HOT 1
- Is this going to be updated for Laravel 5? HOT 4
- Running with view composers HOT 2
- Does Laravel 5.1 work? HOT 1
- test
- Usage in the laravel API resource HOT 1
- Test
- Blah
- blah
- test
- test
- xxdas
- test
- PHP 8.2 warnings HOT 1
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 presenter.