我已经看到了这个问题的多个不同答案,其中没有一个能够继续使用表单模型绑定。似乎表单将标记提交为数组,实际上应该是一个字符串。有什么想法吗?
控制器:
/**
* Save new news
*
* @param Request $request
* @return mixed
*/
public function store(NewsRequest $request)
{
// Create News object and save all form data
$news = News::create($request->all());
// Rename image file and move to public/images
$image = $request->file('image');
$path = "/images/";
$ext = $image->getClientOriginalExtension();
$name = str_random(12) . $ext;
$image->move(public_path() . $path, $name);
$news->image = $path . $name;
// Save new image path to News object
$news->save();
//associate with sandbox, if not already
$news->sandboxes()->sync($request->input('sandboxes'));
//populate news_tag pivot table with chosen tags
$news->tags()->sync($request->input('tags'));
return redirect()->action('FP\NewsController@index');
}
这是我的追踪:
ErrorException in helpers.php line 747:
preg_replace(): Parameter mismatch, pattern is a string while replacement is an array
in helpers.php line 747
at HandleExceptions->handleError('2', 'preg_replace(): Parameter mismatch, pattern is a string while replacement is an array', '/home/greg/Projects/Code/sandboxserver/vendor/laravel/framework/src/Illuminate/Support/helpers.php', '747', array('search' => '\?', 'replace' => array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), 'subject' => 'insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (fafeafadfa, hgtshjnfxsnbdg, https://www.thing.com, 2016-11-12 21:30, ?, ?, ?, ?, ?, ?)', 'value' => array('1', '2')))
at preg_replace('/\?/', array('1', '2'), 'insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (fafeafadfa, hgtshjnfxsnbdg, https://www.thing.com, 2016-11-12 21:30, ?, ?, ?, ?, ?, ?)', '1') in helpers.php line 747
at str_replace_array('\?', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), 'insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (fafeafadfa, hgtshjnfxsnbdg, https://www.thing.com, 2016-11-12 21:30, ?, ?, ?, ?, ?, ?)') in QueryException.php line 56
at QueryException->formatMessage('insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), object(PDOException)) in QueryException.php line 39
at QueryException->__construct('insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), object(PDOException)) in Connection.php line 730
at Connection->runQueryCallback('insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), object(Closure)) in Connection.php line 685
at Connection->run('insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), object(Closure)) in Connection.php line 458
at Connection->statement('insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53')) in Connection.php line 414
at Connection->insert('insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53')) in Processor.php line 32
at Processor->processInsertGetId(object(Builder), 'insert into `news` (`title`, `author`, `url`, `publish_at`, `tags`, `snippet`, `content`, `image`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), 'id') in Builder.php line 2107
at Builder->insertGetId(array('fafeafadfa', 'hgtshjnfxsnbdg', 'https://www.thing.com', '2016-11-12 21:30', array('1', '2'), 'gdsagasgbvsa', '<p>bgsagsghsghsgb</p>', object(UploadedFile), '2016-11-13 01:31:53', '2016-11-13 01:31:53'), 'id')
at call_user_func_array(array(object(Builder), 'insertGetId'), array(array('title' => 'fafeafadfa', 'author' => 'hgtshjnfxsnbdg', 'url' => 'https://www.thing.com', 'publish_at' => '2016-11-12 21:30', 'tags' => array('1', '2'), 'snippet' => 'gdsagasgbvsa', 'content' => '<p>bgsagsghsghsgb</p>', 'image' => object(UploadedFile), 'updated_at' => '2016-11-13 01:31:53', 'created_at' => '2016-11-13 01:31:53'), 'id')) in Builder.php line 1423
at Builder->__call('insertGetId', array(array('title' => 'fafeafadfa', 'author' => 'hgtshjnfxsnbdg', 'url' => 'https://www.thing.com', 'publish_at' => '2016-11-12 21:30', 'tags' => array('1', '2'), 'snippet' => 'gdsagasgbvsa', 'content' => '<p>bgsagsghsghsgb</p>', 'image' => object(UploadedFile), 'updated_at' => '2016-11-13 01:31:53', 'created_at' => '2016-11-13 01:31:53'), 'id')) in Model.php line 1628
at Model->insertAndSetId(object(Builder), array('title' => 'fafeafadfa', 'author' => 'hgtshjnfxsnbdg', 'url' => 'https://www.thing.com', 'publish_at' => '2016-11-12 21:30', 'tags' => array('1', '2'), 'snippet' => 'gdsagasgbvsa', 'content' => '<p>bgsagsghsghsgb</p>', 'image' => object(UploadedFile), 'updated_at' => '2016-11-13 01:31:53', 'created_at' => '2016-11-13 01:31:53')) in Model.php line 1597
at Model->performInsert(object(Builder), array()) in Model.php line 1488
at Model->save() in Model.php line 574
at Model::create(array('_token' => 'dz4MGABUXPSV2fyT4rYcatpEcOnDVkjL0RX9tX9B', 'title' => 'fafeafadfa', 'author' => 'hgtshjnfxsnbdg', 'url' => 'https://www.thing.com', 'publish_at' => '2016-11-12 21:30', 'sandboxes' => array('1'), 'tags' => array('1', '2'), 'snippet' => 'gdsagasgbvsa', 'content' => '<p>bgsagsghsghsgb</p>', 'image' => object(UploadedFile))) in NewsController.php line 56
at NewsController->store(object(NewsRequest))
at call_user_func_array(array(object(NewsController), 'store'), array(object(NewsRequest))) in Controller.php line 80
at Controller->callAction('store', array(object(NewsRequest))) in ControllerDispatcher.php line 146
at ControllerDispatcher->call(object(NewsController), object(Route), 'store') in ControllerDispatcher.php line 94
at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 96
at ControllerDispatcher->callWithinStack(object(NewsController), object(Route), object(Request), 'store') in ControllerDispatcher.php line 54
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\FP\NewsController', 'store') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 51
at Authenticate->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure))
at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 53
at require_once('/home/greg/Projects/Code/sandboxserver/public/index.php') in server.php line 21
答案 0 :(得分:0)
答案非常简单,因为我们之前的团队将标签作为表格列&gt;而在“新闻”雄辩模型中设置了标签字段。&gt; 。一旦我将其删除,现在全部修好了!