Your code looks ok ... do you get any error?
Try with this
public function store(Request $request){
$input=$request->all();
$input['added_at']=Carbon::now();
Book::create($input);
return redirect('books');
}
I want to make a book shop management system. Now, to add new books details in the booklist I created a form. But the problem is when I press the submit button though it redirect me to the expected page but the data of the form is not saved to database.
this is my route:
Route::post('books', 'BooksController@store');
this is the table Schema::create('books', function (Blueprint $table) { $table->increments('id'); $table->string('title'); $table->string('author'); $table->string('publisher'); $table->timestamp('year'); $table->integer('price'); $table->string('image_path'); $table->timestamp('added_at');
$table->timestamps();
});
this is the controller
public function store(){
$book=Request::all();
$book['added_at']=Carbon::now();
Book::create($book);
return redirect('books');
}
and the model is class Book extends Model { protected $fillable=[ 'title', 'author', 'publisher', 'year', 'price', 'image_path', 'added_at'
];
}
Please or to participate in this conversation.