我正在使用laravel 4.1构建一个api.我有一个工作正常的表.但响应来自我不想要的枢轴属性.正如您将在我的示例中看到的,我必须有两个表名:trip和users.我不希望在响应中看到数据透视表属性.这是一个例子:
[
{
"id": 140,
"name_first": "hasan",
"name_last": "hasibul",
"profile_image": "/assets/images/default-profile-img.png",
"created_at": "2013-09-18 08:19:50",
"last_login": "2013-12-26 11:28:44",
"status": "active",
"last_update": "2013-10-15 13:40:47",
"google_refresh_token": null,
"is_admin": 1,
"updated_at": null,
"pivot": {
"trip_id": 200,
"user_id": 140
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的用户模型:
public function trips(){
return $this->belongsToMany('Trip');
}
Run Code Online (Sandbox Code Playgroud)
这是我的旅行模型:
public function users(){
return $this->belongsToMany('User');
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
public function index($tripId)
{
$userCollection = Trip::find($tripId)->users;
return $userCollection;
}
Run Code Online (Sandbox Code Playgroud)
这是我的路线:
//get all the users belongs to the trip
Route::get('trips/{tripId}/users', array(
'as' => 'trips/users/index',
'uses' => 'TripUserController@index'
)); …Run Code Online (Sandbox Code Playgroud) 我正在用Laravel创建api.我有一个表名"rfp_requests",我的ORM模型名称是Request.我在Laravel文档中看到为了使用自定义表名,我必须指定我所做的表名.但它仍然无法正常工作.这是我的型号代码:
class Request extends Eloquent {
/**
* Database table used by model
* @var string
*/
protected $table = 'rfp_requests';
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器代码.我也试图看到执行的查询.但它没有显示任何东西.
class RequestController extends BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$requestData = Request::all();
$queries = DB::getQueryLog();
Log::info($queries);
return $requestData;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的路线代码:
Route::resource('requests', 'RequestController');
Route::model('requests', 'Request');
Run Code Online (Sandbox Code Playgroud)
当我点击网址时,我看到空阵列.我不确定我做错了什么.有人可以告诉我在Laravel Eloquent ORM中指定自定义表名的正确方法是什么.
我正在尝试在Amazon EC2上安装nginx.nginx部分运行正常.但是我遇到了php-fpm的问题.当我运行服务php-fpm启动时出现错误:EC2上的php-fpm错误:进程管理器丢失(静态,动态或按需).我正在学习本教程:http://codingsteps.com/install-php-fpm-nginx-mysql-on-ec2-with-amazon-linux-ami/.我不知道为什么我会收到这个错误.有人可以帮我安装php-fpm.
我是一名新的Laarvel用户.在我使用Codeigniter之前.在Codeigniter中,通过执行tail -f很容易看到日志文件和执行时间.我看到Laravel在app/storage/logs目录中有日志文件.问题是日志文件只给我错误,它没有给出任何执行时间或查询时间.有人可以帮助我如何从命令行查看执行时间?我也尝试过Ioic-sharma探测器.