title: Error: Attempt to assign property "name" on null
body: <p>I am Working On a E-commerce Project with Laravel-8. I am facing a problem in editing the products og this E-commerce site. when I am clicking on 'Update' after editing the details of any product. It's Saying &quot;Error
  Attempt to assign property &quot;name&quot; on null&quot;</p>
  <p>Here's My Web.php code</p>
  <pre><code>&lt;?php
  
  use Illuminate\Support\Facades\Route;
  use App\Http\Livewire\Homecomponent;
  use App\Http\Livewire\Shopcomponent;
  use App\Http\Livewire\Cartcomponent;
  use App\Http\Livewire\Checkoutcomponent;
  use App\Http\Livewire\Detailscomponent;
  use App\Http\Livewire\Categorycomponent;
  use App\Http\Livewire\Headersearchcomponent;
  use App\Http\Livewire\Searchcomponent;
  use App\Http\Livewire\user\UserDashboardComponent;
  use App\Http\Livewire\admin\AdminDashboardComponent;
  use App\Http\Livewire\admin\Admincategorycomponent;
  use App\Http\Livewire\admin\Adminaddcategorycomponent;
  use App\Http\Livewire\admin\Admineditcategorycomponent;
  use App\Http\Livewire\admin\Adminproductcomponent;
  use App\Http\Livewire\admin\Adminaddproductcomponent;
  use App\Http\Livewire\admin\Admineditproductcomponent;
  
  /*
  |--------------------------------------------------------------------------
  | Web Routes
  |--------------------------------------------------------------------------
  |
  | Here is where you can register web routes for your application. These
  | routes are loaded by the RouteServiceProvider within a group which
  | contains the &quot;web&quot; middleware group. Now create something great!
  |
  */
  
  //Route::get('/', function () {
  //   return view('welcome');
  //});
  
  Route::get('/',Homecomponent::class);
  
  Route::get('/shop',Shopcomponent::class);
  
  Route::get('/cart',Cartcomponent::class)-&gt;name('product.cart');
  
  Route::get('/checkout',Checkoutcomponent::class);
  
  Route::get('/product/{slug}',Detailscomponent::class)-&gt;name('product.details');
  
  Route::get('/product-category/{category_slug}',categorycomponent::class)-&gt;name('product.category');
  
  Route::get('/search',searchcomponent::class)-&gt;name('product.search');
  
  
  //Route::middleware(['auth:sanctum', 'verified'])-&gt;get('/dashboard', function () {
  //    return view('dashboard');
  //})-&gt;name('dashboard');
  
  //For User or Coustomer
  Route::middleware(['auth:sanctum', 'verified'])-&gt;group(function(){
          Route::get('/user/dashboard',UserDashboardComponent::class)-&gt;name('user.dashboard');
  });
  
  //For Admin
  Route::middleware(['auth:sanctum', 'verified','authadmin'])-&gt;group(function(){
          Route::get('/admin/dashboard',AdminDashboardComponent::class)-&gt;name('admin.dashboard');
          Route::get('/admin/categories',Admincategorycomponent::class)-&gt;name('admin.categories');
          Route::get('/admin/category/add',Adminaddcategorycomponent::class)-&gt;name('admin.addcategory');
          Route::get('/admin/category/edit/{category_slug}',Admineditcategorycomponent::class)-&gt;name('admin.editcategory');
          Route::get('/admin/products',Adminproductcomponent::class)-&gt;name('admin.products');
          Route::get('/admin/product/add',Adminaddproductcomponent::class)-&gt;name('admin.addproduct');
          Route::get('/admin/product/edit/{product_slug}',Admineditproductcomponent::class)-&gt;name('admin.editproduct');
  });
  </code></pre>
  <p>Here's my editproductcomponent.php(class)  Code-&gt;</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Livewire\Admin;
  
  use Livewire\Component;
  use App\Models\Product;
  use App\Models\Category;
  use Illuminate\Support\Str;
  use Carbon\Carbon;
  use Livewire\WithFileUploads;
  
  class Admineditproductcomponent extends Component
  {
      use WithFileUploads;
  
      public $product_slug;
      public $product_id;
      public $name;
      public $slug;
      public $short_description;
      public $description;
      public $regular_price;
      public $sell_price;
      public $SKU;
      public $stock_status;
      public $featured;
      public $quantity;
      public $image;
      public $category_id;
      public $newimage;
  
      public function mount($product_slug)
      {
          $product = Product::where('slug',$product_slug)-&gt;first();
  
          $this-&gt;name = $product-&gt;name;
          $this-&gt;slug = $product-&gt;slug;
          $this-&gt;short_description = $product-&gt;short_description;
          $this-&gt;description = $product-&gt;description;
          $this-&gt;regular_price = $product-&gt;regular_price;
          $this-&gt;sell_price = $product-&gt;sell_price;
          $this-&gt;SKU = $product-&gt;SKU;
          $this-&gt;stock_status = $product-&gt;stock_status;
          $this-&gt;featured = $product-&gt;featured;
          $this-&gt;quantity = $product-&gt;quantity;
          $this-&gt;image = $product-&gt;image;
          $this-&gt;category_id = $product-&gt;category_id;
          $this-&gt;product_id = $product-&gt;product_id;
  
      }
  
      public function generateSlug()
      {
          $this-&gt;slug = Str::slug($this-&gt;name,'-');
      }
  
      public function updateproduct()
      {
          $product = Product::find($this-&gt;product_id);
          $product-&gt;name = $this-&gt;name;
          $product-&gt;slug = $this-&gt;slug;
          $product-&gt;short_description = $this-&gt;short_description;
          $product-&gt;description = $this-&gt;description;
          $product-&gt;regular_price = $this-&gt;regular_price;
          $product-&gt;sell_price = $this-&gt;sell_price;
          $product-&gt;SKU = $this-&gt;SKU;
          $product-&gt;stock_status = $this-&gt;stock_status;
          $product-&gt;featured = $this-&gt;featured;
          $product-&gt;quantity = $this-&gt;quantity;
          if($this-&gt;newimage)
          {
              $imageName = Carbon::now()-&gt;timestamp. '.' . $this-&gt;newimage-&gt;extension();
              $this-&gt;newimage-&gt;storeAs('products',$imageName);
              $product-&gt;image = $imageName;
          }
          $product-&gt;category_id = $this-&gt;category_id;
          $product-&gt;save();
          session()-&gt;flash('message','Product has been Updated Successfully');
      }
  
      public function render()
      {
          $categories = Category::all();
          return view('livewire.admin.admineditproductcomponent',['categories' =&gt; $categories])-&gt;layout('layouts.base');
      }
  }
  
  </code></pre>
  <p>Here's my editproductcomponent.blade.php(View)  Code-&gt;</p>
  <pre><code>&lt;div&gt;
      &lt;div class=&quot;container&quot;style=&quot;padding:30px 0;&quot;&gt;
          &lt;div class=&quot;row&quot;&gt;
              &lt;div class=&quot;col-md-12&quot;&gt;
                  &lt;div class=&quot;panel panel-default&quot;&gt;
                      &lt;div class=&quot;panel-heading&quot;&gt;
                          &lt;div class=&quot;row&quot;&gt;
                              &lt;div class=&quot;col-md-6&quot;&gt;
                                  Edit Product
                              &lt;/div&gt;
                              &lt;div class=&quot;col-md-6&quot;&gt;
                                  &lt;a href=&quot;{{route('admin.products')}}&quot; class=&quot;btn btn-success pull-right&quot;&gt;All Products&lt;/a&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class=&quot;panel-body&quot;&gt;
                          &lt;form action=&quot;&quot; class=&quot;form-horizontal&quot; enctype=&quot;multipart/form-data&quot; wire:submit.prevent=&quot;updateproduct&quot;&gt;
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Product Name&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;input type=&quot;text&quot; placeholder=&quot;Product Name&quot; class=&quot;form-control input-md&quot; wire:model=&quot;name&quot; wire:keyup=&quot;generateSlug&quot;&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Product Slug&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;input type=&quot;text&quot; placeholder=&quot;Product Slug&quot; class=&quot;form-control input-md&quot; wire:model=&quot;slug&quot;&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Short Description&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;textarea name=&quot;&quot; id=&quot;&quot; cols=&quot;30&quot; rows=&quot;10&quot; placeholder=&quot;Short Description&quot; class=&quot;form-control&quot; wire:model=&quot;short_description&quot;&gt;&lt;/textarea&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Description&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;textarea name=&quot;&quot; id=&quot;&quot; cols=&quot;30&quot; rows=&quot;10&quot; placeholder=&quot;Description&quot; class=&quot;form-control&quot; wire:model=&quot;description&quot;&gt;&lt;/textarea&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Regular Price&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;input type=&quot;text&quot; placeholder=&quot;Regular Price&quot; class=&quot;form-control input-md&quot; wire:model=&quot;regular_price&quot;&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Sell Price&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;input type=&quot;text&quot; placeholder=&quot;Sell Price&quot; class=&quot;form-control input-md&quot; wire:model=&quot;sell_price&quot;&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;SKU&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;input type=&quot;text&quot; placeholder=&quot;SKU&quot; class=&quot;form-control input-md&quot; wire:model=&quot;SKU&quot;&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Stock&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;select name=&quot;&quot; id=&quot;&quot; class=&quot;form-control&quot; wire:model=&quot;stock_status&quot;&gt;
                                          &lt;option value=&quot;instock&quot;&gt;InStock&lt;/option&gt;
                                          &lt;option value=&quot;outofstock&quot;&gt;Out of Stock&lt;/option&gt;
                                      &lt;/select&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Featured&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;select name=&quot;&quot; id=&quot;&quot; class=&quot;form-control&quot; wire:model=&quot;featured&quot;&gt;
                                          &lt;option value=&quot;0&quot;&gt;No&lt;/option&gt;
                                          &lt;option value=&quot;1&quot;&gt;Yes&lt;/option&gt;
                                      &lt;/select&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Quantity&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;input type=&quot;number&quot; placeholder=&quot;Quantity&quot; class=&quot;form-control input-md&quot; wire:model=&quot;quantity&quot;&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Product Image&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;input type=&quot;file&quot; class=&quot;input-file&quot; wire:model=&quot;newimage&quot;&gt;
                                      @if($newimage)
                                          &lt;img src=&quot;{{$newimage-&gt;temporaryUrl()}}&quot; width=&quot;120&quot;&gt;
                                      @else
                                          &lt;img src=&quot;{{asset('assets/images/products')}}/{{$image}}&quot; width=&quot;120&quot; alt=&quot;&quot;&gt;
                                      @endif
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;Category&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;select name=&quot;&quot; id=&quot;&quot; class=&quot;form-control&quot; wire:model=&quot;category_id&quot;&gt;
                                          &lt;option value=&quot;&quot;&gt;Select Category&lt;/option&gt;
                                          @foreach ($categories as $category)
                                              &lt;option value=&quot;{{$category-&gt;id}}&quot;&gt;{{$category-&gt;name}}&lt;/option&gt;
                                          @endforeach
                                      &lt;/select&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class=&quot;form-group&quot;&gt;
                                  &lt;label for=&quot;&quot; class=&quot;col-md-4 control-label&quot;&gt;&lt;/label&gt;
                                  &lt;div class=&quot;col-md-4&quot;&gt;
                                      &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Update&lt;/button&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
                      @if(Session::has('message'))
                              &lt;div class=&quot;alert alert-success&quot; role=&quot;alert&quot;&gt;{{Session::get('message')}}&lt;/div&gt;
                      @endif
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;                                                                                                                      
      &lt;/div&gt;
  &lt;/div&gt;
  
  </code></pre>
  <p>Please Help Me....</p>