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?

dmikam
  • 992
  • 1
  • 18
  • 27
  • 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. – dmikam Jan 25 '22 at 09:12
  • Instead of sending the model through the route, why don't you declare it directly on the livewire component? – haruk1515 Oct 20 '22 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! – dmikam Oct 21 '22 at 12:09

0 Answers0