0
votes

Any idea why this fail?

Routes

Route::get('/artikel','artikelController@index')->name('artikel.index');
Route::get('/artikel/create','artikelController@create')->name('artikel.create');
Route::post('/artikel','artikelController@store')->name('artikel.store');
Route::get('/artikel/{id}','artikelController@show')->name('artikel.show');

artikelController

public function create()
{
    return view ('artikel.create');
}

public function store(request $request)
{
    $input = $request->all();
    artikel::create($input);

    return redirect(route('artikel.index'));
}    

Model

protected $fillable = ['judul', 'users_id'];

protected $casts = [];
1
where is the problem? where is the question? - boolfalse
you don't have any controller method for show - Erfan Ahmed
Please add your migration file of the affected table. - frankfurt-laravel

1 Answers

0
votes

As you can see in the returned error:

General error: 1364 Field 'kategori_artikel_id' doesn't have a default value

your app is trying to create a record without a value for the column kategori_artikel_id, and this column isn't being defined as nullable and doens't have a default value.

You may have sent this value in your request but it isn't being included when trying to store de value.. the reason for this is that you haven't registered that property/column in the $fillable config of your model.

Try this:

protected $fillable = ['judul', 'users_id', 'kategori_artikel_id'];
//                                           ^^^^^^^^^^^^^^^^^^^

You can get more info in the Mass Assignment section of the documentation.