2

I have a problem with my upload in laravel. My view :

{{ Form::open(array('url'=>'administration/video/create','method' => 'post','files'=>true)) }}
        <p>
            {{ Form::label('Titlu:') }}
            {{ Form::text('title',null,array('class'=>'form-control')) }}
        </p>
        <p>
            {{ Form::label('Description:') }}
            {{ Form::text('description',null,array('class'=>'form-control')) }}
        </p>
        <p>
            {{ Form::label('image','Imagine:') }}
            {{ Form::file('image','',array('id'=>'','class'=>'')) }}
        </p>
        <p>
            {{ Form::label('video','Video:') }}
            {{ Form::file('video','',array('id'=>'','class'=>'')) }}
        </p>
            {{ Form::submit('Add',array('class'=>'btn btn-primary')) }}
            {{ Form::reset('Reset',array('class'=>'btn btn-success')) }}
            {{ Form::close() }}

My controller:

public function postCreate(){
    $video = new \Video();
    $video->title       = Input::get('title');
    $video->description = Input::get('description');
    $video->video_image = '';
    $video->video_name  = '';
    if(Input::hasFile('image')) {
        $sImagePermalink = \Url_Lib::makePermalink($video->title);
        $image = Input::file('image');
        $filename = $sImagePermalink . "." . $image->getClientOriginalExtension();
        $path = public_path('content/video/' . $filename);
        Image::make($image->getRealPath())->resize(468, 249)->save($path);
        $video->video_image = 'content/video/' . $filename;

        $videoDocument = Input::file('video');
        $videofile = $sImagePermalink . "." . $videoDocument->getClientOriginalExtension();
        $pathVideo = public_path('content/video/' . $videofile);
        Input::file('video')->move('content/video/', $pathVideo);
        $video->video_name = 'content/video/' . $videofile;
    }

    $video->save();
    return Redirect::to('/administration/video/add/')
        ->with('message_succes','Video added');
}

I get an error : SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null I don't understand why? Please help me.

Harea Costea
  • 275
  • 5
  • 19
  • Do `dd(Input::get('title'))` to make sure it's getting what you think it's getting. – ceejayoz Jan 26 '15 at 20:01
  • The problem it when I tried to upload video – Harea Costea Jan 26 '15 at 20:05
  • 1
    This is a database error. It tells you that you're trying to save empty value for `title` column, which is not nullable. I would listen to the suggestion ceejayoz proposed above. Put `dd(Input::get('title'))` in your `postCreate()` method and then try to upload a video. – lesssugar Jan 26 '15 at 21:32

1 Answers1

3

Issue is when you create table / schema, you didn't set your title column can be nullable,

You can solve it with two ways. you can either change your table schema and set the title column nullable,

Schema::create("yourtablename" , function($table){
 ........
  $table->string("title")->nullable();
 ........
});

or instead of Input::get("title") you can try with default value so even it is empty or null it will have a default value.

 Input::get("title" , "No title"); 
serdar.sanri
  • 2,217
  • 1
  • 17
  • 21