【发布时间】:2015-02-28 17:06:42
【问题描述】:
我是移动应用程序(Android/iOS)开发人员,在没有我们的 php 开发人员的情况下,我想在我们的数据库中添加另一个表并 POST 和 GET 一些数据并存储在新表中。
Laravel 4 安装在我们的服务器中,并使用一些基本的 cPanel、phpMyAdmin 和 php 信息,我尝试在我们现有的数据库中创建一个新表。
首先我累了并使用 phpMyAdmin 创建了一个表,然后我添加了这样的模型文件
<?php
class Record extends Eloquent {
protected $table = 'requestRecords';
protected $guarded = array();
public $timestamps = true;
}
但是,当我尝试使用这种语法将数据添加到我的 route.php 文件(我使用 phpMyAdmin 手动创建)中的 requestRecords 时,什么也没发生:
Route::post('api/v1/FLRequest', function()
{
//check right inputs sent to us.
if( !Request::has('userId') or
!Request::has('userName') or
!Request::has('timeStamp') or
!Request::has('requestFor') or
!Request::has('nKey'))
return Response::json(array(
'status' => "error",
'message' => "Missing Parameter"),
500
);
$inputs = Request::all();
if($inputs['nKey']!= "nKey_Goes_Here")
return Response::json(array(
'status' => "error",
'message' => "Wrong Request"),
500
);
$addRecord = Record::create(array(
'userName' => $inputs['userName']));
if($addRecord!==FALSE)
{
return Response::json(array(
'status' => "success",
'message' => "Record Updated"),
200
);
}
else
{
return Response::json(array(
'status' => "error",
'message' => "Failed Updating Record"),
401
);
}
实际上我没有得到 200 和 401,但我得到了HTTP 500 Internal Server Error。
然后我尝试使用模式添加表,所以我在 database/migrations 文件夹中创建了一个 php 文件,命名为:2015_01_02_104814_create_requestRecords_table.php 并在那里添加这些代码:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateRequestRecordsTable extends Migration {
public function up()
{
Schema::create('requestRecords', function($table) {
$table->increments('id');
$table->string('userId',255);
$table->string('userName', 255);
$table->string('timeStamp', 255);
$table->string('payLoad',255);
$table->string('requestFor',255);
$table->string('bToken',255);
$table->string('bSituation',255);
});
}
public function down()
{
Schema::drop('requestRecords');
}
}
再次尝试添加数据后,我既没有得到 200 也没有得到 401,但得到了HTTP 500 Internal Server Error。
更多细节是我的控制器和模型:
文件/app/controllers/RequestRecordsController.php中的控制器:
<?php
class RequestRecordsController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
}
}
?>
/app/models/Record.php 中的模型:
<?php
class Record extends Eloquent {
protected $table = 'requestRecords';
protected $guarded = array();
public $timestamps = true;
}
我做错了什么?
谢谢:)
【问题讨论】:
-
那你得到什么回应?只是空白?另外,你能确保你没有用
create填写的值都是可选的/可为空的吗?因为在您的迁移中它们不是。 -
@lukasgeiter 我得到了
HTTP 500 Internal Server Error。 -
@lukasgeiter 实际上,我尝试仅在列上创建表(我填写的唯一一个
create),但再次出现相同的 500 内部错误。 -
请检查
app/storage/logs/laravel.log并使用错误消息更新您的问题 -
@lukasgeiter 实际上我记得那天,我们的 php 开发人员说我们不需要任何日志,并且为了防止存储警告,他禁用了日志记录。 :((((