我滿足了這個錯誤。一般錯誤:1366錯誤的整數值Laravel
我解釋一下這個視圖。
我有一個窗體來創建一個新項目,當我創建它時,我隱藏窗體並保存它,然後我渲染其他窗體來創建翻譯,我創建它並保存它,最後我渲染一個其他形式來創建客戶端,我創建並保存它。
在這一刻,只是在相同的功能,我想保存另一個表中的另一個值。
我想保存在client_projects中保存在數據庫中的最後一個client_id和project_id的值。
所以我試試這個:
$client_project = new Client_Project();
$client_project->client_id = DB::table('clients')->where('id', DB::raw("(select max(id) from clients)"))->get();
$client_project->project_id = DB::table('projects')->where('id', DB::raw("(select max(id) from projects)"))->get();
$client_project->save();
但它給我的標題::
SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '[{"id":49,"name":"hola","slug":"hola","priority":1,"created_at":"2017-08-03 13:53:35","updated_at":"2017-08-03 13:53:35"}]' for column 'client_id' at row 1 (SQL: insert into `client_project` (`client_id`, `project_id`, `updated_at`, `created_at`) values ([{"id":49,"name":"hola","slug":"hola","priority":1,"created_at":"2017-08-03 13:53:35","updated_at":"2017-08-03 13:53:35"}], [{"id":40,"slug":"1","order":40,"public":1,"pathheader":"\/tmp\/phpf8NUkb","pathhome":"\/tmp\/php9zepk7","created_at":"2017-08-03 13:49:53","updated_at":"2017-08-03 13:49:53"}], 2017-08-03 13:53:35, 2017-08-03 13:53:35))
完整的功能,其中我創建客戶端的錯誤,我嘗試創建client_projects被這
public function storeProjectsClients(Request $request){
$client = new Client();
$client->name = $request->input("nameClient");
$client->slug = $request->input("slugClient");
$client->priority = $request->input("priorityClient");
$client->save();
$client_project = new Client_Project();
$client_project->client_id = DB::table('clients')->where('id', DB::raw("(select max(id) from clients)"))->get();
$client_project->project_id = DB::table('projects')->where('id', DB::raw("(select max(id) from projects)"))->get();
$client_project->save();
}
我知道最好通過使用json的project_id和client_id的值,因爲如果有些用戶在同一時間這樣做會產生問題,但無論如何,這隻適用於我。
任何幫助將不勝感激。
試想一下,在插入查詢。您正在嘗試編寫「 [{」id「:49,」name「:」hola「,」slug「:」hola「,」priority「:1,」created_at「:」2017-08-03 13:53 :35「,」updated_at「:」2017-08-03 13:53:35「}]」到需要整數的列。 –
我檢查了很多次.. id是整數,name是字符串,slug是字符串,優先級是整數。你在哪裏發現錯誤? –
您正在寫整個字符串「[{」id「:49,」name「:」hola「,」slug「:」hola ....「,以期望一個整數的數據庫列..... –