Connection.php 第 729 行中的 QueryException:SQLSTATE[23000]:Laravel 5.2

Posted

技术标签:

【中文标题】Connection.php 第 729 行中的 QueryException:SQLSTATE[23000]:Laravel 5.2【英文标题】:QueryException in Connection.php line 729: SQLSTATE[23000]: Laravel 5.2 【发布时间】:2017-04-19 03:58:46 【问题描述】:

下午好。

我正在尝试使用一种方法在 laravel 中上传多张图片,但它不能完全正常工作。

我遇到的问题是因为我有一个表格文件,我将在其中注册我上传的与名为属性的表格相关的图像。

产生的错误如下:

Connection.php 第 729 行中的 2/2 QueryException: SQLSTATE[23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(erpinmobiliaria.files, CONSTRAINT files_property_id_foreign FOREIGN KEY (property_id) REFERENCES properties (@987654326 @) ON DELETE CASCADE) (SQL: insert into files (name, updated_at, created_at) 值 (5844676fdd1e8.jpg, 2016-12-04 18:58:55, 2016-12-04 18 :58:55))

这是一堆错误:

1. in Connection.php line 729
2. at Connection->runQueryCallback('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55'), object(Closure)) in Connection.php line 685
3. at Connection->run('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55'), object(Closure)) in Connection.php line 458
4. at Connection->statement('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55')) in Connection.php line 414
5. at Connection->insert('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55')) in Processor.php line 32
6. at Processor->processInsertGetId(object(Builder), 'insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55'), 'id') in Builder.php line 2107
7. at Builder->insertGetId(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id')
8. at call_user_func_array(array(object(Builder), 'insertGetId'), array(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id')) in Builder.php line 1423
9. at Builder->__call('insertGetId', array(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id')) in Model.php line 1628
10. at Builder->insertGetId(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id') in Model.php line 1628
11. at Model->insertAndSetId(object(Builder), array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55')) in Model.php line 1597
12. at Model->performInsert(object(Builder), array()) in Model.php line 1488
13. at Model->save() in Model.php line 574
14. at Model::create(array('name' => '5844676fdd1e8.jpg')) in PropertyController.php line 90
15. at PropertyController->store(object(Request))
16. at call_user_func_array(array(object(PropertyController), 'store'), array(object(Request))) in Controller.php line 80
17. at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 146
18. at ControllerDispatcher->call(object(PropertyController), object(Route), 'store') in ControllerDispatcher.php line 94
19. at ControllerDispatcher->Illuminate\Routing\closure(object(Request))
20. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
21. at Pipeline->Illuminate\Routing\closure(object(Request))
22. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
23. at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
24. at ControllerDispatcher->callWithinStack(object(PropertyController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
25. at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\PropertyController', 'store') in Route.php line 174
26. at Route->runController(object(Request)) in Route.php line 140
27. at Route->run(object(Request)) in Router.php line 724
28. at Router->Illuminate\Routing\closure(object(Request))
29. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
30. at Pipeline->Illuminate\Routing\closure(object(Request)) in Authenticate.php line 28
31. at Authenticate->handle(object(Request), object(Closure))
32. at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
33. at Pipeline->Illuminate\Pipeline\closure(object(Request))
34. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
35. at Pipeline->Illuminate\Routing\closure(object(Request)) in VerifyCsrfToken.php line 29
36. at VerifyCsrfToken->handle(object(Request), object(Closure))
37. at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
38. at Pipeline->Illuminate\Pipeline\closure(object(Request))
39. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
40. at Pipeline->Illuminate\Routing\closure(object(Request)) in ShareErrorsFromSession.php line 49
41. at ShareErrorsFromSession->handle(object(Request), object(Closure))
42. at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
43. at Pipeline->Illuminate\Pipeline\closure(object(Request))
44. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
45. at Pipeline->Illuminate\Routing\closure(object(Request)) in StartSession.php line 64
46. at StartSession->handle(object(Request), object(Closure))
47. at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
48. at Pipeline->Illuminate\Pipeline\closure(object(Request))
49. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
50. at Pipeline->Illuminate\Routing\closure(object(Request)) in AddQueuedCookiesToResponse.php line 37
51. at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
52. at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
53. at Pipeline->Illuminate\Pipeline\closure(object(Request))
54. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
55. at Pipeline->Illuminate\Routing\closure(object(Request)) in EncryptCookies.php line 59
56. at EncryptCookies->handle(object(Request), object(Closure))
57. at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
58. at Pipeline->Illuminate\Pipeline\closure(object(Request))
59. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
60. at Pipeline->Illuminate\Routing\closure(object(Request))
61. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
62. at Pipeline->then(object(Closure)) in Router.php line 726
63. at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
64. at Router->dispatchToRoute(object(Request)) in Router.php line 675
65. at Router->dispatch(object(Request)) in Kernel.php line 246
66. at Kernel->Illuminate\Foundation\Http\closure(object(Request))
67. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
68. at Pipeline->Illuminate\Routing\closure(object(Request)) in Debugbar.php line 51
69. at Debugbar->handle(object(Request), object(Closure))
70. at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
71. at Pipeline->Illuminate\Pipeline\closure(object(Request))
72. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
73. at Pipeline->Illuminate\Routing\closure(object(Request)) in CheckForMaintenanceMode.php line 44
74. at CheckForMaintenanceMode->handle(object(Request), object(Closure))
75. at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
76. at Pipeline->Illuminate\Pipeline\closure(object(Request))
77. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
78. at Pipeline->Illuminate\Routing\closure(object(Request))
79. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
80. at Pipeline->then(object(Closure)) in Kernel.php line 132
81. at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
82. at Kernel->handle(object(Request)) in index.php line 54

Connection.php 第 457 行中的 1/2 PDOException: SQLSTATE[23000]:完整性约束违规:1452 无法添加或更新子行:外键约束失败(erpinmobiliaria.files,CONSTRAINT files_property_id_foreign FOREIGN KEY (property_id) REFERENCES properties (@987654337 @) 删除级联)

1. in Connection.php line 457
2. at PDOStatement->execute(array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55')) in Connection.php line 457
3. at Connection->Illuminate\Database\closure(object(mysqlConnection), 'insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55')) in Connection.php line 722
4. at Connection->runQueryCallback('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55'), object(Closure)) in Connection.php line 685
5. at Connection->run('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55'), object(Closure)) in Connection.php line 458
6. at Connection->statement('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55')) in Connection.php line 414
7. at Connection->insert('insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55')) in Processor.php line 32
8. at Processor->processInsertGetId(object(Builder), 'insert into `files` (`name`, `updated_at`, `created_at`) values (?, ?, ?)', array('5844676fdd1e8.jpg', '2016-12-04 18:58:55', '2016-12-04 18:58:55'), 'id') in Builder.php line 2107
9. at Builder->insertGetId(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id')
10. at call_user_func_array(array(object(Builder), 'insertGetId'), array(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id')) in Builder.php line 1423
11. at Builder->__call('insertGetId', array(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id')) in Model.php line 1628
12. at Builder->insertGetId(array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55'), 'id') in Model.php line 1628
13. at Model->insertAndSetId(object(Builder), array('name' => '5844676fdd1e8.jpg', 'updated_at' => '2016-12-04 18:58:55', 'created_at' => '2016-12-04 18:58:55')) in Model.php line 1597
14. at Model->performInsert(object(Builder), array()) in Model.php line 1488
15. at Model->save() in Model.php line 574
16. at Model::create(array('name' => '5844676fdd1e8.jpg')) in PropertyController.php line 90
17. at PropertyController->store(object(Request))
18. at call_user_func_array(array(object(PropertyController), 'store'), array(object(Request))) in Controller.php line 80
19. at Controller->callAction('store', array(object(Request))) in ControllerDispatcher.php line 146
20. at ControllerDispatcher->call(object(PropertyController), object(Route), 'store') in ControllerDispatcher.php line 94
21. at ControllerDispatcher->Illuminate\Routing\closure(object(Request))
22. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
23. at Pipeline->Illuminate\Routing\closure(object(Request))
24. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
25. at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
26. at ControllerDispatcher->callWithinStack(object(PropertyController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
27. at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\PropertyController', 'store') in Route.php line 174
28. at Route->runController(object(Request)) in Route.php line 140
29. at Route->run(object(Request)) in Router.php line 724
30. at Router->Illuminate\Routing\closure(object(Request))
31. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
32. at Pipeline->Illuminate\Routing\closure(object(Request)) in Authenticate.php line 28
33. at Authenticate->handle(object(Request), object(Closure))
34. at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
35. at Pipeline->Illuminate\Pipeline\closure(object(Request))
36. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
37. at Pipeline->Illuminate\Routing\closure(object(Request)) in VerifyCsrfToken.php line 29
38. at VerifyCsrfToken->handle(object(Request), object(Closure))
39. at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
40. at Pipeline->Illuminate\Pipeline\closure(object(Request))
41. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
42. at Pipeline->Illuminate\Routing\closure(object(Request)) in ShareErrorsFromSession.php line 49
43. at ShareErrorsFromSession->handle(object(Request), object(Closure))
44. at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
45. at Pipeline->Illuminate\Pipeline\closure(object(Request))
46. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
47. at Pipeline->Illuminate\Routing\closure(object(Request)) in StartSession.php line 64
48. at StartSession->handle(object(Request), object(Closure))
49. at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
50. at Pipeline->Illuminate\Pipeline\closure(object(Request))
51. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
52. at Pipeline->Illuminate\Routing\closure(object(Request)) in AddQueuedCookiesToResponse.php line 37
53. at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
54. at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
55. at Pipeline->Illuminate\Pipeline\closure(object(Request))
56. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
57. at Pipeline->Illuminate\Routing\closure(object(Request)) in EncryptCookies.php line 59
58. at EncryptCookies->handle(object(Request), object(Closure))
59. at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
60. at Pipeline->Illuminate\Pipeline\closure(object(Request))
61. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
62. at Pipeline->Illuminate\Routing\closure(object(Request))
63. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
64. at Pipeline->then(object(Closure)) in Router.php line 726
65. at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
66. at Router->dispatchToRoute(object(Request)) in Router.php line 675
67. at Router->dispatch(object(Request)) in Kernel.php line 246
68. at Kernel->Illuminate\Foundation\Http\closure(object(Request))
69. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
70. at Pipeline->Illuminate\Routing\closure(object(Request)) in Debugbar.php line 51
71. at Debugbar->handle(object(Request), object(Closure))
72. at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
73. at Pipeline->Illuminate\Pipeline\closure(object(Request))
74. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
75. at Pipeline->Illuminate\Routing\closure(object(Request)) in CheckForMaintenanceMode.php line 44
76. at CheckForMaintenanceMode->handle(object(Request), object(Closure))
77. at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
78. at Pipeline->Illuminate\Pipeline\closure(object(Request))
79. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
80. at Pipeline->Illuminate\Routing\closure(object(Request))
81. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
82. at Pipeline->then(object(Closure)) in Kernel.php line 132
83. at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
84. at Kernel->handle(object(Request)) in index.php line 54

这是我的 Properties 表迁移。

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePropertiesTable extends Migration

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    
        Schema::create('properties', function (Blueprint $table) 
            $table->increments('id');
            $table->integer('category_id')->unsigned();
            $table->foreign('category_id')
                  ->references('id')
                  ->on('categories')
                  ->onDelete('cascade');
            $table->integer('term_id')->unsigned();
            $table->foreign('term_id')
                  ->references('id')
                  ->on('terms')
                  ->onDelete('cascade');
            $table->string('address');
            $table->string('location');//Localidad
            $table->string('l_number');//Número de ubicación propiedad
            $table->integer('province_id')->unsigned();
            $table->foreign('province_id')
                  ->references('id')
                  ->on('provinces')
                  ->onDelete('cascade');
            $table->string('ctime');//Tiempo de construcción de la propiedad (años).
            $table->string('mconstruction');//Metros de construcción (Mt2).
            $table->string('ground');//Metros de terreno (Mt2).
            $table->string('level');//Nivel/Piso.
            $table->string('elevator');//Asscensores.
            $table->string('price');
            $table->integer('currency_id')->unsigned();            
            $table->foreign('currency_id')
                  ->references('id')
                  ->on('currencies')
                  ->onDelete('cascade');
            $table->integer('client_id')->unsigned();            
            $table->foreign('client_id')
                  ->references('id')
                  ->on('clients')
                  ->onDelete('cascade');
            $table->timestamps();
        );

        DB::update("ALTER TABLE properties AUTO_INCREMENT = 1000;");
    

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    
        Schema::drop('properties');
    

这是我的 Files 表迁移。

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateFilesTable extends Migration

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    
        Schema::create('files', function (Blueprint $table) 
            $table->increments('id');
            $table->string('name');
            //$table->string('route');
            //$table->string('type');
            //$table->string('size');
            $table->integer('property_id')->unsigned();//Relación propiedad.
            $table->foreign('property_id')
                  ->references('id')
                  ->on('properties')
                  ->onDelete('cascade');
            $table->timestamps();
        );
    

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    
        Schema::drop('files');
    

我的财产控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Intervention\Image\Exception\NotReadableException;

use Illuminate\Support\Facades\Input;

use App\Http\Requests;
use App\Client;
use App\Category;
use App\Term;
use App\Province;
use App\Property;
use App\Currency;
use App\User;
use App\File;
use Image;
use Hash;

class PropertyController extends Controller

    public function index(Request $request)
    
        $data = Property::orderBy('id','ASC')->paginate(5);

        return view('properties.index',compact('data', 'properties'))
            ->with('i', ($request->input('page', 1) - 1) * 5);
    

    public function create()
    
        $categories = Category::orderBy('id', 'asc')->lists('name', 'id');

        $terms = Term::orderBy('id', 'asc')->lists('name', 'id');

        $provinces = Province::orderBy('id', 'asc')->lists('name', 'id');

        $currencies = Currency::orderBy('id', 'asc')->lists('name', 'id');

        $clients = Client::orderBy('id', 'asc')->lists('name', 'id');

        return view('properties.create', compact('categories', 'terms', 'provinces', 'currencies', 'clients'));
    

    public function store(Request $request)
    
        $properties = Property::create([
            'category_id'         => $request->get('category_id'),
            'term_id'             => $request->get('term_id'),
            'address'             => $request->get('address'),
            'location'            => $request->get('location'),
            'l_number'            => $request->get('l_number'),
            'province_id'         => $request->get('province_id'),
            'ctime'               => $request->get('ctime'),
            'mconstruction'       => $request->get('mconstruction'),
            'ground'              => $request->get('ground'),
            'level'               => $request->get('level'),
            'elevator'            => $request->get('elevator'),
            'price'               => $request->get('price'),
            'currency_id'         => $request->get('currency_id'),
            'client_id'           => $request->get('client_id')
        ]);

        $images = $request->file('avatar'); 
        foreach ($images as $image) 
        
            $rules = array(
                'avatar' => 'required|mimes:png,gif,jpeg,jpg|max:20000'
            );
            $validator = \Validator::make(array('avatar'=> $image), $rules);
            if (! $validator->passes())
            
                return redirect()->back()->withErrors($validator);
            
            $extension = $image->getClientOriginalExtension();
            $filename = uniqid() . '.' . $extension;
            $path = public_path() . 'uploads/products/';

            Image::make($image)->resize(300, 200)->save( public_path('uploads/products/' . $filename ) );

            //Move file into uploads folder 
            $image->move($path, $filename);
            //Insert file name in db
            $image = File::create([ 
                'name'      => $filename,
            ]);
        

        return redirect()->route('properties.index')
                        ->with('success','Inmueble agregado satisfactoriamente!!!');
    

这是表单的一部分,我只包含了上传文件的输入:

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12 margin-tb">
            <div class="pull-left">
                <h2>Registrar Inmuebles</h2>
            </div>
            <br>
        </div>
    </div>

    <div class="row"> 

    !! Form::open(array('route' => 'properties.store', 'method' => 'POST', 'enctype' => 'multipart/form-data', 'name' => 'files', 'files' => 'true')) !!

        <div class="col-md-4 col-xs-4">
        <br>
            <div class="form-group">
                <div class="text-center">
                    <a href="#" class="thumbnail">
                        <img src=" asset('/uploads/products/default.jpg') " class="avatar img-thumbnail"  style="height: 180px; width: 100%;">
                        <h6>Agrega las imagenes del inmueble...</h6>
                        <input type="file" name="avatar[]" multiple="true" class="text-center center-block well well-sm" style="width: 100%;">
                    </a>
                </div>
            </div>

        </div>

        <div class="col-md-12 col-xs-12">
            <div class="pull-right">
                <a class="btn btn-warning btn-xs" href=" route('properties.index') " data-toggle="tooltip" rel="tooltip" data-placement="top" title="Retornar">
                <i class="material-icons">arrow_back</i>
            </a>

            <button type="submit" class="btn btn-success btn-xs" data-toggle="tooltip" rel="tooltip" data-placement="top" title="Guardar registro"><i class="material-icons">save</i>
            </button>
            </div> 
        </div>

    !! Form::close() !!

</div>

【问题讨论】:

【参考方案1】:

您正在向数据库中创建文件条目,但未在新记录中分配先前创建的属性 ID。

您的数据库由 name 和 property_id 字段组成。您只保存了一个名称字段。

 $image = File::create([ 
            'name'      => $filename,
            'property_id => $properties->id

        ]);

【讨论】:

非常感谢,我有点困惑,但您的回答和评论是正确的,它帮助我解决了这个错误。

以上是关于Connection.php 第 729 行中的 QueryException:SQLSTATE[23000]:Laravel 5.2的主要内容,如果未能解决你的问题,请参考以下文章

DataTable 从行中获取修改后的数据

解决迁移错误

laravel QueryException 行 770

前端面试每日 3+1 —— 第729天

laravel 雄辩的数据透视表查询“不明确的列名”

HtmlServiceProvider.php 第 36 行中的 FatalErrorException:laravel