title: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into `products`..... in laravel-8
body: <p>i am facing a problem is SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into <code>products</code> (<code>name</code>, <code>detail</code>, <code>color</code>, <code>logo</code>, <code>image</code>, <code>updated_at</code>, <code>created_at</code>) values (fdsf, sdf, #7536d3, 20210522184540.jpg, 20210522184540.JPG, 2021-05-22 18:45:40, 2021-05-22 18:45:40)). i want a user have meny products
  here is my ProductController.php</p>
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use App\Models\Product;
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\DB;
  use App\Http\Requests\Admin\StoreTagsRequest;
  use App\Models\User;
  use Illuminate\Support\Facades\Hash;
  
  class ProductController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          $products = Product::latest()-&gt;paginate(20);
  
          return view('products.index',compact('products'))
  
              -&gt;with('i', (request()-&gt;input('page', 5) - 1) * 5);
      }
  
      function authapi(Request $request)
      {
          $user = User:: where('email', $request-&gt;email)-&gt;first();
          if(!$user || !Hash::check($request-&gt;password, $user-&gt;password)){
              return response([
                  'message' =&gt; ['These credentials do not match our records.']
              ],404);
          }
  
          $token = $user -&gt; createToken('my-app-token')-&gt;plainTextToken;
  
          $response = [
              'user' =&gt; $user,
              'token' =&gt; $token
          ];
  
          return response($response,201);
      }
  
      function all_app_jsons(){
          return Product::all();
      }
  
      function search_by_name($name){
          return Product::where('name','like','%'.$name.'%')-&gt;get();
      }
  
      function search_by_id($id){
          return Product::where('id',$id)-&gt;get();
      }
      /**
       * Show the form for creating a new resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function create()
      {
          return view('products.create');
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(Request $request)
      {
          //$tag = Product::create($request-&gt;all());
  
          //return redirect()-&gt;route('admin.tags.index');
          $request-&gt;validate([
              'name' =&gt; 'required',
              'detail' =&gt; 'required',
              'color' =&gt; 'required',
              'image' =&gt; 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
              'logo' =&gt; 'required|mimes:jpeg,png,jpg,gif,svg|max:1024',
          ]);
  
          $input = $request-&gt;all();
  
          if ($image = $request-&gt;file('image')) {
              $destinationPath = 'image/';
              $profileImage = date('YmdHis') . &quot;.&quot; . $image-&gt;getClientOriginalExtension();
              $image-&gt;move($destinationPath, $profileImage);
              $input['image'] = &quot;$profileImage&quot;;
          }
  
          if ($logo = $request-&gt;file('logo')) {
              $destinationPath = 'logo/';
              $profileLogo = date('YmdHis') . &quot;.&quot; . $logo-&gt;getClientOriginalExtension();
              $logo-&gt;move($destinationPath, $profileLogo);
              $input['logo'] = &quot;$profileLogo&quot;;
          }
  
          Product::create($input);
  
          return redirect()-&gt;route('products.index')
                          -&gt;with('success','Product created successfully.');
      }
  
      /**
       * Display the specified resource.
       *
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function show(Product $product)
      {
          return view('products.show',compact('product'));
      }
  
      /**
       * Show the form for editing the specified resource.
       *
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function edit(Product $product)
      {
          return view('products.edit',compact('product'));
      }
  
      /**
       * Update the specified resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function update(Request $request, Product $product)
      {
          $request-&gt;validate([
              'name' =&gt; 'required',
              'detail' =&gt; 'required',
              'color' =&gt; 'required'
          ]);
  
          $input = $request-&gt;all();
  
          if ($image = $request-&gt;file('image')) {
              $destinationPath = 'image/';
              $profileImage = date('YmdHis') . &quot;.&quot; . $image-&gt;getClientOriginalExtension();
              $image-&gt;move($destinationPath, $profileImage);
              $input['image'] = &quot;$profileImage&quot;;
          }else{
              unset($input['image']);
          }
  
          if ($logo = $request-&gt;file('logo')) {
              $destinationPath = 'logo/';
              $profileLogo = date('YmdHis') . &quot;.&quot; . $logo-&gt;getClientOriginalExtension();
              $logo-&gt;move($destinationPath, $profileLogo);
              $input['logo'] = &quot;$profileLogo&quot;;
          }else{
              unset($input['logo']);
          }
  
          $product-&gt;update($input);
  
          return redirect()-&gt;route('products.index')
                          -&gt;with('success','Product updated successfully');
      }
  
      /**
       * Remove the specified resource from storage.
       *
       * @param  \App\Product  $product
       * @return \Illuminate\Http\Response
       */
      public function destroy(Product $product)
      {
          $product-&gt;delete();
  
          return redirect()-&gt;route('products.index')
                          -&gt;with('success','Product deleted successfully');
      }
  
      // function indextwo(){
      //     //return DB::select(&quot;select * from  products&quot;);
      //    //DB::table('products')-&gt;orderBy('id','desc')-&gt;first();
      //    return Product::orderBy('id', 'DESC')-&gt;first();
      // }
  
  }
  </code></pre>
  <p>here is my model product.php</p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Database\Eloquent\Model;
  
  class Product extends Model
  {
      use HasFactory;
  
      protected $fillable = [
          'name', 'detail', 'image','color','logo'
      ];
  
      public function user(){
          return $this-&gt;belongsTo(User::class);
      }
  }
  </code></pre>
  <p>here is model user.php</p>
  <pre><code>&lt;?php
  
  namespace App\Models;
  
  use Illuminate\Contracts\Auth\MustVerifyEmail;
  use Illuminate\Database\Eloquent\Factories\HasFactory;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  use Illuminate\Notifications\Notifiable;
  use Laravel\Fortify\TwoFactorAuthenticatable;
  use Laravel\Jetstream\HasProfilePhoto;
  use Laravel\Sanctum\HasApiTokens;
  
  class User extends Authenticatable
  {
      use HasApiTokens;
      use HasFactory;
      use HasProfilePhoto;
      use Notifiable;
      use TwoFactorAuthenticatable;
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'name',
          'email',
          'password',
      ];
  
      /**
       * The attributes that should be hidden for arrays.
       *
       * @var array
       */
      protected $hidden = [
          'password',
          'remember_token',
          'two_factor_recovery_codes',
          'two_factor_secret',
      ];
  
      /**
       * The attributes that should be cast to native types.
       *
       * @var array
       */
      protected $casts = [
          'email_verified_at' =&gt; 'datetime',
      ];
  
      /**
       * The accessors to append to the model's array form.
       *
       * @var array
       */
      protected $appends = [
          'profile_photo_url',
      ];
  
      public function products(){
          return $this-&gt;hasMany(Product::class);
      }
  }
  </code></pre>
  <p>here is product table</p>
  <pre><code>  public function up()
      {
          Schema::create('products', function (Blueprint $table) {
              $table-&gt;id();
              $table-&gt;string('name');
              $table-&gt;text('detail');
              $table-&gt;string('color');
              $table-&gt;string('image');
              $table-&gt;string('logo');
              $table-&gt;unsignedBigInteger('user_id');
              $table-&gt;timestamps();
          });
          Schema::table('products', function (Blueprint $table){
              $table-&gt;foreign('user_id')-&gt;references('id')-&gt;on('users');
  
          });
      }
  </code></pre>