mardi 12 octobre 2021

Laravel :doesn't have a default value

SQLSTATE[HY000]: General error: 1364 Field 'product_name' doesn't have a default value

<?php

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use App\product;

class productController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data = [];
        $data['title'] = "index page";
        return view('product.index', $data);
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $data = [];
        $data['title'] = "create page";
        return view('product.create', $data);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $data = $request->all();
        //    $product=new product();  
        //    $product->product_name=$data['pro_name'];  /
        //    $product->description=$data['description'];
        //    $product->Starting_Date_and_Time=$data['SDAT'];
        //    $product->Ending_Date_and_Time=$data['EDAT'];
        //    $product->save();
        $product = product::create($data);   
        dd($product);
    }

    /**
     * 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)
    {
        return view('product.edit');
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        return 'product delete';
    }
}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire