【问题标题】:Upload video with Laravel使用 Laravel 上传视频
【发布时间】:2015-03-25 07:36:29
【问题描述】:

我在 laravel 中的上传有问题。我的看法:

{{ 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() }}

我的控制器:

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');
}

我得到一个错误:SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null 我不明白为什么?请帮帮我。

【问题讨论】:

  • dd(Input::get('title')) 以确保它得到你认为它得到的东西。
  • 上传视频时的问题
  • 这是一个数据库错误。它告诉您您正在尝试为 title 列保存空值,该列不可为空。我会听听ceejayoz 上面提出的建议。将dd(Input::get('title')) 放入您的postCreate() 方法中,然后尝试上传视频。

标签: php laravel laravel-4 laravel-3


【解决方案1】:

问题是当你创建表/模式时,你没有设置你的标题列可以为空,

您可以通过两种方式解决它。 您可以更改表架构并将标题列设置为空,

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

或者代替 Input::get("title") 您可以尝试使用默认值,因此即使它为空或 null 它也将具有默认值。

 Input::get("title" , "No title"); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 2018-07-07
    相关资源
    最近更新 更多