Home > Software design >  Laravel 9 Field doesn't have a default value
Laravel 9 Field doesn't have a default value

Time:09-07

In my project, I got many forms, so I've decided to specify each one with an iscription field, for exemple: Kids' form => <input = 'hidden' name = 'inscripted_in' value = 'kids'>. I want to set each one with a default value, but whenever I sign in, I get this error message: SQLSTATE[HY000]: General error: 1364 Field 'inscripted_at' doesn't have a default value Although when I go to Laravel Debug, I still get the inserted constant value, what's the problem?

This is one of my forms

                <div >
                    <input type="hidden" name="inscripted_at" value="Adults">
                    <input type="hidden" name="status" value="pending">
                </div>

my controller:

public function store(Request $req)
   {
    $this->validate($req,[
        'name' => 'required|max:120',
        'surname' => 'required|max:120',
        'job' => 'required|max:120',
        'day' => 'required',
        'month' => 'required',
        'year' => 'required',
        'hobby' => 'required|max:120',
        'help' => 'required|max:120',
        'place' => 'required|max:120',
        'residence' => 'required|max:120',
        'email' => 'required|email|unique:users',
        'photo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        'scholar_year' => 'required|max:120',
        'tel' => 'required|regex:/(05)[0-9]{8}/',
        ]);

        Chababounauser::create($req->all());

      
       return redirect()->route('chababounausers.index')
                       ->with('success','chababouna User inserted successfully.');
   }

CodePudding user response:

Check the fillable property of the Chababounauser model.

P.S.: Please, don't put spaces in HTML between attribute name and it's value.

CodePudding user response:

Isn't 'inscripted_at' a default column in the database giving the date of inscription ? If so, you can't default a value to that kind of output.

  • Related