Mates, I'm havin a problem to save a record to the database. As I understand the error, it seems as it doesn't exist an 'id_purchase' in the table. But it does. The code I'm using is the following:
<?php
class Purchproducts_Controller extends Base_Controller {
public $restful = true;
public function get_index()
{
$purchases = Purchproduct::where('id_hostel', '=', Session::get('id_hostel'))->get();
$response = array();
foreach($purchases as $purch){
$response[] = $purch->attributes;
}
return json_encode($response);
}
public function post_create()
{
$data = Input::json();
$purchase = Purchproduct::create(
array(
'id_hostel' => Session::get('id_hostel'),
'id_products' => $data->id_products,
'id_purchase,' => $data->id_purchases,
'qty' => $data->qty
)
);
return json_encode($purchase->attributes);
}
}
The error screen:
Unhandled Exception
Message:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id_purchase,' in 'field list'
SQL: INSERT INTO `ehm_purchproducts` (`id_hostel`, `id_products`, `id_purchase,`, `qty`, `updated_at`, `created_at`) VALUES (?, ?, ?, ?, ?, ?)
Bindings: array (
0 => 1,
1 => '2',
2 => 2,
3 => '12',
4 => '2013-04-16 22:00:32',
5 => '2013-04-16 22:00:32',
)
Location:
/home/pablo/htdocs/insdev/laravel/laravel/database/connection.php on line 263
Stack Trace:
#0 /home/pablo/htdocs/insdev/laravel/laravel/database/connection.php(183): Laravel\Database\Connection->execute('INSERT INTO `eh...', Array)
#1 /home/pablo/htdocs/insdev/laravel/laravel/database/query.php(823): Laravel\Database\Connection->query('INSERT INTO `eh...', Array)
#2 [internal function]: Laravel\Database\Query->insert_get_id(Array, 'id')
#3 /home/pablo/htdocs/insdev/laravel/laravel/database/eloquent/query.php(283): call_user_func_array(Array, Array)
#4 /home/pablo/htdocs/insdev/laravel/laravel/database/eloquent/model.php(390): Laravel\Database\Eloquent\Query->__call('insert_get_id', Array)
#5 /home/pablo/htdocs/insdev/laravel/laravel/database/eloquent/model.php(390): Laravel\Database\Eloquent\Query->insert_get_id(Array, 'id')
#6 /home/pablo/htdocs/insdev/laravel/laravel/database/eloquent/model.php(205): Laravel\Database\Eloquent\Model->save()
#7 /home/pablo/htdocs/insdev/laravel/application/controllers/purchproducts.php(27): Laravel\Database\Eloquent\Model::create(Array)
#8 [internal function]: Purchproducts_Controller->post_create()
#9 /home/pablo/htdocs/insdev/laravel/laravel/routing/controller.php(325): call_user_func_array(Array, Array)
#10 /home/pablo/htdocs/insdev/laravel/laravel/routing/controller.php(285): Laravel\Routing\Controller->response('create', Array)
#11 /home/pablo/htdocs/insdev/laravel/laravel/routing/controller.php(165): Laravel\Routing\Controller->execute('create', Array)
#12 /home/pablo/htdocs/insdev/laravel/laravel/routing/route.php(153): Laravel\Routing\Controller::call('purchproducts@c...', Array)
#13 /home/pablo/htdocs/insdev/laravel/laravel/routing/route.php(124): Laravel\Routing\Route->response()
#14 /home/pablo/htdocs/insdev/laravel/laravel/laravel.php(167): Laravel\Routing\Route->call()
#15 /home/pablo/htdocs/insdev/laravel/public/index.php(34): require('/home/pablo/htd...')
#16 {main}
The table structure:
CREATE TABLE IF NOT EXISTS `ehm_purchproducts` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_hostel` int(11) NOT NULL,
`id_products` int(11) NOT NULL,
`id_purchase` int(11) NOT NULL,
`recibo` varchar(200) COLLATE utf8_spanish_ci NOT NULL,
`qty` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish_ci AUTO_INCREMENT=1 ;
Any ideas?
'id_purchase,' => $data->id_purchases,
the is comma in there, that's why it throwing error no found field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With