I'm using Laravel and trying to build a gallery, i'm testing the upload of a file to a db but i when i click submit i get the error " Illuminate \ Database \ QueryException (23000) SQLSTATE[23000]: Integrity constraint violation: 1048 Column
I've set up a GalleryController and the code is as follows
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;
class GalleryController extends Controller
{
// List Galleries
public function index (){
//Render View
return view ('gallery/index');
}
// Show Create From
public function create(){
//Render View
return view ('gallery/create');
}
// Store Gallery
public function store(Request $request){
// Get Request Input
$name = $request->input ('name');
$description = $request->input ('description');
$cover_image = $request->input ('cover_image');
$owner_id = 1;
// Check Image Upload
if($cover_image){
$cover_image_filename = $cover_image->getClientOriginalName();
$cover_image->move(public_path('images'), $cover_image_filename);
} else {
$cover_image_filename = 'noimage.jpg';
}
//Insert Gallery
DB::table('galleries')->insert(
[
'name' => $name,
'description' => $description,
'cover_image' => $cover_image,
'owner_id' => $owner_id,
]
);
//Redirect
return \Redirect::route('gallery.index')-> with('message', 'Gallery Created');
}
//Show Gallery Photos
public function show($id){
die ($id);
`
The main.blade.php calls the code using
@ if(Session::has('message'))
<div class="alert alert-info">
{{Session::get('message')}}
</div>
@ endif;
My .env DB is set to root and password is blank too.
If any more info is needed please advise.
Thanks