我有一个像这样的 Laravel 查询-
public function rearrangePhoto(Request $request)
{
$ordering = $request->input('ordering');
return UserSlidePhoto::where('user_id', Auth::id())
->select(
'thumbnail_name',
'original_image_name',
'id'
)
->orderBy('created_at', $ordering)
->get();
}
像这样的模型-
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class UserSlidePhoto extends Model
{
protected $table="users_slides_photos";
protected $fillable=['user_id','social_image_id','provider_key','provider_id','thumbnail_name'];
public function users()
{
return $this->belongsTo('App\User')->withTimestamps();
}
}
我得到这样的回应-
[{
"thumbnail_name": "2-hR1vt2ZOOesbpGv00MRbGDYyGAMEqU.jpg",
"original_image_name": "qweqqwe.jpg",
"id": 49
},
{
"thumbnail_name": "2-xqiUrT2lJkEBQ0aA3MmZARmWlAq0BT.jpg",
"original_image_name": "tyutjh.jpg",
"id": 50
},
{
"thumbnail_name": "2-s0zzdC275XqvrT2llBQ4h9sugadCHk.jpg",
"original_image_name": "asdas.jpg",
"id": 101
}]
我喜欢得到这样的回应——
[{
"thumbnail_name": "base_url/2-hR1vt2ZOOesbpGv00MRbGDYyGAMEqU.jpg",
"original_image_name": "qweqqwe.jpg",
"id": 49
},
{
"thumbnail_name": "base_url/2-xqiUrT2lJkEBQ0aA3MmZARmWlAq0BT.jpg",
"original_image_name": "tyutjh.jpg",
"id": 50
},
{
"thumbnail_name": "base_url/2-s0zzdC275XqvrT2llBQ4h9sugadCHk.jpg",
"original_image_name": "asdas.jpg",
"id": 101
}]
所以我所做的是——
public function rearrangePhoto(Request $request)
{
$ordering = $request->input('ordering');
$base_url = "base_url/";
return UserSlidePhoto::where('user_id', Auth::id())
->select(
$base_url . DB::raw('thumbnail_name'),
'original_image_name',
'id'
)
->orderBy('created_at', $ordering)
->get();
}
我收到了这个错误-
有人可以帮忙吗?
提前感谢您的帮助....