I try to insert the session user id in form but it was show me error this:

> 
> SQLSTATE[HY000]: General error: 1364 Field 'user\_id' doesn't have a default value (SQL: insert into `stocks` (`product_name`, `product_code`, `details`, `price`, `cost`, `quntity`, `updated_at`, `created_at`) values (basmati Rice, 23432, dskljsdlkks;lk; ;ks;lvk, 40, 75, 100kg, 2019-09-09 08:43:12, 2019-09-09 08:43:12))
> 
> 
> 

I think error on this line of code which I used for store the session id

```
 <input type="hidden" name="user_id" 
               value="{{ $request->session()->put('user',$request->input('id')) }}"
> class="form-control">

```

This is my create blade page, which I make a form and try to insert the form fields.

```
     @extends('layouts.app')
@section('content')

<div class="row">
 <div class="col-md-12">
   @if(count($errors) > 0)
  <div class="alert alert-danger">
   <ul>
   @foreach($errors->all() as $error)
    <li>{{$error}}</li>
   @endforeach
   </ul>
  </div>
  @endif
  @if(\Session::has('success'))
  <div class="alert alert-success">
   <p>{{ \Session::get('success') }}</p>
  </div>
  @endif
  <div class="card">
  <div class="card-header">
  <h5 class="title">Add New Product on Stock</h5>
  </div>
  <div class="card-body">

  <form method="post" action="{{url('stock')}}">
   {{csrf_field()}}
      <div class="row">
        <div class="col-md-6 pr-1">
            <div class="form-group">
              <label>Product Name</label>
             <input type="text" name="user_id" 
    value="{{Auth::user()->id }}" class="form-control">
              <input type="text" name="product_name" class="form-control" placeholder="Enter Product Name" />
            </div>
         </div>
         <div class="col-md-6 pl-1">
            <div class="form-group">
              <label>Product Code</label>
               <input type="text" name="product_code" class="form-control" placeholder="Enter product_code" />
            </div>
          </div>
      </div>
  </br>
   <div class="row">
                    <div class="col-md-4 pr-1">
                      <div class="form-group">
                        <label>Price</label>
                        <input type="text" name="price" class="form-control" placeholder="Enter price" />
                      </div>
                    </div>
                    <div class="col-md-4 px-1">
                      <div class="form-group">
                        <label>Cost</label>
                        <input type="text" name="cost" class="form-control" placeholder="Enter cost" />
                      </div>
                    </div>
                    <div class="col-md-4 pl-1">
                      <div class="form-group">
                        <label>Quantity</label>
                        <input type="text" name="quntity" class="form-control" placeholder="Enter quntity" />
                      </div>
                    </div>
                  </div>
          </br> 
          <div class="row">
                    <div class="col-md-12">
                      <div class="form-group">
                       <label>Details</label>
    <input type="text" name="details" class="form-control" placeholder="Enter details" />
                      </div>
                    </div>

          </div>
   <div class="form-group">
    <input type="submit" class="btn btn-primary" />
   </div>
  </form>
 </div>
</div>
@endsection

```

this is my controller file of stock

```
       <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Stock;
use Auth;
class StockController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $stocks = Stock::all()->toArray();
        return view('stock.index', compact('stocks'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        return view('stock.create');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, [
            'user_id' =>'required',
            'product_name'    =>  'required',
            'product_code'     =>  'required',
             'details'    =>  'required',
            'price'     =>  'required',
            'cost'    =>  'required',
            'quntity'     =>  'required'
        ]);
        $stock = new Stock([
          'user_id' => Auth::user()->user_id,
            'product_name'    =>  $request->get('product_name'),
            'product_code'    =>  $request->get('product_code'),
            'details'    =>  $request->get('details'),
            'price'    =>  $request->get('price'),
            'cost'    =>  $request->get('cost'),
            'quntity'     =>  $request->get('quntity')
        ]);
        $stock->save();
        return redirect()->route('stock.index')->with('success', 'Data Added');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
       $stock = Stock::find($id);
        return view('stock.edit', compact('stock', 'id'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
         $this->validate($request, [
             'product_name'    =>  'required',
            'product_code'     =>  'required',
             'details'    =>  'required',
            'price'     =>  'required',
            'cost'    =>  'required',
            'quntity'     =>  'required'
        ]);
        $stock = Stock::find($id);
        $stock->product_name = $request->get('product_name');
        $stock->product_code = $request->get('product_code');
        $stock->details = $request->get('details');
        $stock->price = $request->get('price');
        $stock->cost = $request->get('cost');
        $stock->quntity = $request->get('quntity');
        $stock->save();
        return redirect()->route('stock.index')->with('success', 'Data Updated');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
         $stock = Stock::find($id);
        $stock->delete();
        return redirect()->route('stock.index')->with('success', 'Data Deleted');
    }
    }

```