Need Clarification about some doubts on coding

Hi Purvesh,

I have one small doubt regarding code, may be it is out of the box , but please do clarify for below query

public function edit(Banner $banner)

when i echo $banner this  giving me json string.

When i create the module by following the steps, for my module it is giving me empty array. 

 public function edit(Testmodel $test){

echo $test


Please reply for above query.


Purvesh had replied 8 months ago


In Laravel that concept called Route Model Binding. To implement in your code base 

Step1: Setup Route based on the method argument. 

Route::get('category/{category}', 'CategoryViewController@view')->name('category.view');

Step2:  Inside your method variable needs to match your route key bind:(category´╗┐). By default URI should be http://localhost/category/ID_OF_CATEGORY

public function view(Request $request, Category $category)
dd($category); // Object of Category

I hope it helps. If you need more help please read this laravel doc.


Aaazan had replied 8 months ago

Thank you Purvesh for your feedback. Your feedback has resolved my query, One more doubt i would like to ask. In edit view you are using _fields.blade in that file you are using below line code, and text box is displaying the db value perfectly. 

@include('avored-ecommerce::forms.text',['name' => 'name','label' => __('')])

When i use the same code as listed below in my module's edit view text box i am not getting the value, i am getting empty text box. Is that i missed something in my code ?

@include('avored-ecommerce::forms.text',['name' => 'title','label' => __('avored-test::test.title')])

Please reply for my query.

Thank you.

Purvesh had replied 8 months ago

reason, why i have a _field.blade.php file exist,

I don't want to repeat form fields code for creating and edit form again and again. 

If you replace your code :

@include('avored-ecommerce::forms.text',['model' => $testModel,'name' => 'title','label' => __('avored-test::test.title')])

It should fill the field value if it exist: