Allow developers to get the current crud entry based on route parameter
See original GitHub issueBug report
What I did
Referenced $this->crud->entry->[property]
within a CRUD controllers setupUpdateOperation()
function when editing an existing entry.
What I expected to happen
A reference to $this->crud->entry to exist.
What happened
The reference to $this->crud->entry is null.
What I’ve already tried to fix it
Nothing.
Backpack, Laravel, PHP, DB version
When I run php artisan backpack:version
the output is:
PHP VERSION:
PHP 7.3.15-3+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Feb 23 2020 07:23:33) ( NTS ) Copyright © 1997-2018 The PHP Group Zend Engine v3.3.15, Copyright © 1998-2018 Zend Technologies with Xdebug v2.9.8, Copyright © 2002-2020, by Derick Rethans with Zend OPcache v7.3.15-3+ubuntu18.04.1+deb.sury.org+1, Copyright © 1999-2018, by Zend Technologies
LARAVEL VERSION:
v7.29.3@93f6d565a07045baa0e4b941ae1f733cd5984d65
BACKPACK VERSION:
4.1.27@bd1bab5dde08df20eebd730ca3a2992e1bf334f7
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
Simple Laravel CRUD with Resource Controllers - DigitalOcean
Creating, reading, updating, and deleting resources is used in pretty much every application. Laravel helps make the process easy using resource ...
Read more >Pass parameters to crud controller Backpack laravel
I want to reach for "league_id" to make filter at GameCrudController. What is the problem in the previous steps and thanks for the...
Read more >Routing to controller actions in ASP.NET Core - Microsoft Learn
Learn how ASP.NET Core MVC uses Routing Middleware to match URLs of incoming requests and map them to actions.
Read more >Working with routes for HTTP APIs - Amazon API Gateway
Routes direct incoming API requests to backend resources. Routes consist of two parts: an HTTP method and a resource path—for example, GET /pets...
Read more >CRUD REST API with Node.js, Express, and PostgreSQL
Our goal is to allow CRUD operations, GET , POST , PUT , and DELETE , on the API, which will run the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Boy do I have good news for you guys 😂🥳🎉🎈
The existing
$this->crud->getCurrentEntry()
does just that 🤯😂, and can be used insidesetupUpdateOperation()
just fine. So this sounds to me like a documentation problem, rather than a feature request right?That’s a valid and very good solution.
Technically if you know how to write stuff inside
setupXXXOperation
you know how to write it insideedit()
. There are developers that prefer to ovewriteedit
andcreate
and add the fields there etc. you have$this->crud
there too.There is documentation on how to overwrite crud operation functions https://backpackforlaravel.com/docs/4.1/crud-operation-update#callbacks
Not sure if it’s something we should provide in core, or even how to do it properly in core if we do it.
We cannot use
setupUpdateDefaults
, Thedefaults
for every operation, are loaded along with theCrudPanel
, so even if you go toListOperation
, you will have theUpdateDefaults
loaded. What you setup insidesetupUpdateOperation
is what is specific only for that operation, and we run it only when the specific operation is called. That said, if we do it insidedefaults
, sometimes we will have the entry, sometimes don’t.Having an helper function like
getEntryFromUrlAttribute($attribute)
does not sound bad at all. That way we could tell devs if they want to get the entry inside thesetupXXXOperation
they could use it, even if we don’t do it as a default for the operation.I am in for anything that helps developers (like myself) to speedup our development, we here (Backpack) just need to make sure that we don’t pollute (more) the CrudPanel with very niche cases.
I don’t think this is a niche case and it could be helpfull for anyone who needs it.
That said, even if we don’t make this into core I would probably just create an addon that adds this functionality to the crud (Crud is macroable, very easy to add anything without polluting the core)
@tabacitu @promatik what you think about this ?
I think yesterday somebody asked about the same in gitter. (changing fields based on the current editing entry).
Thanks for the suggestion @selected-pixel-jameson .
Wish you the best, Pedro