lundi 23 mai 2022

Laravel single blade file used for create and show

Is it possible and recommended that I have one lets say form.blade.php with html form file used for create new data and show existing data by ID.

I want to create this becouse file for insert and dispaly is the some. I want to avoid DRY.

Example: I have product categories, when I create a new category I need create.blade.php a file containing an html form. Now I want to use that same file to display the details of that category that will populate the fields in the fields by the given ID

Controller

   // Create 
   public function create()
   {
      return view('admin.category.form');
   }


  // Show
   public function show(Category $category)
   {
      $category = Category::find($category);

      return view('admin.category.form', [
          'category' => $category
      ]);
   }

Or is it better to make a separate file for insert and separet file for show?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire