1

I'm trying to implement an EasyCRUD full page component that would permit basic operations on indicated model. Just for the simplicity, all models would have the same structure (id, name, timestamps, etc.). The idea is to define multiple routes using this component providing it a model name like so:

// For CRUD operations on Country model
Route::get('country', \App\Http\Livewire\EasyCrud::class /*, ['model' => Country::class]*/)->name('country');
// For CRUD operations on Profession model
Route::get('profession', \App\Http\Livewire\EasyCrud::class /*, ['model' => Profession::class]*/)->name('profession');
...

The problem is that there is no third parameter in Route::get|post|etc method. And the only possible way to pass some parameters to the component, afaik, is through url-parameters binding. But I would like not to expose it to user. So is there a way to pass these additional parameters to full page components?

3
  • Ok, it looks like I can use setDefaults on the Route to add some additional data. Route::get('country', \App\Http\Livewire\EasyCrud::class)->setDefaults([ 'model' => Country::class]). But in any case, I am not sure if it is the right/optimal way to do this. Any suggestions are accepted. Commented Jan 25, 2022 at 9:12
  • Instead of sending the model through the route, why don't you declare it directly on the livewire component? Commented Oct 20, 2022 at 11:21
  • 1
    @haruk1515 Because the idea was for the same Livewire component to be used to render CRUDs for different models... And it really works with setDefaults! But in the end I'm doing just what you suggest - there are many livewire components extending EasyCrud class and each one has it's own model assigned. Works very well. And the functionality now is pretty powerfull. Thanks for the suggestion in any case! Commented Oct 21, 2022 at 12:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.