我想知道是否可以为项目资源和集合资源定义不同的数据.
对于收集我只想发送,['id', 'title', 'slug']但项目资源将包含额外的细节['id', 'title', 'slug', 'user', etc.]
我希望实现以下目标:
class PageResource extends Resource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'user' => [
'id' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
],
];
}
}
class PageResourceCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* …Run Code Online (Sandbox Code Playgroud) 我应该如何管理多语言索引(例如:page/page_translations模型应该成为page_en/page_fr索引).我正在使用" Dimsav\Translatable "包.
页面模型:id,status_id,created_at,updated_at
PageTranslation模型:id,page_id,locale,title,slug,body
Algolia为此提供了支持(https://www.algolia.com/doc/guides/search/multilingual-search/),但我不确定如何使用Laravel Scout实现这一目标.
我想到的唯一解决方案是在存储语言环境的相同索引中索引两个语言行(来自翻译模型)并在搜索上应用条件.
Algolia
objectID = 1,title ='英文标题',locale_id ='1'
objectID = 2,title ='Franch title',locale_id ='2'
$pages = App\PageTranslation::search('Star Trek')->where('locale_id', 1)->get();
或者更好的方法?也许分别索引page/page_translations并在两者中搜索?
我希望实现以下目标:
pages_en index:objectID = 1,title ='英文标题'等.
pages_fr index:objectID = 2,title ='Franch title'等.
$pages = App\Page::search('Star Trek')->where('locale', 'en')->get();
当我导入索引一切正常(包括关系).
问题是主模型不关注关系.
当我更新关系时,索引也不会更新.
Cache::tags在修改关系时,有没有办法使用类似的东西来更新索引?或许是另一种方式.
我将Laravel 5.1更新为5.2,事件不再播出.
我正在使用带有php 7和hhvm,Node 5.3.0,Redis 3.0.6的Laravel家园.
Redis工作正常.(我尝试过Redis :: publish).
我解雇了这个事件,但我没有收到任何消息.
活动课程
namespace App\Events;
use App\Events\Event;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class UserSignedUp extends Event implements ShouldBroadcast
{
use SerializesModels;
public $username;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct($username)
{print_r($username);
$this->username = $username;
}
/**
* Get the channels the event should be broadcast on.
*
* @return array
*/
public function broadcastOn()
{
return ['test-channel'];
}
}
Run Code Online (Sandbox Code Playgroud)
路线
Route::get('event', function () {
$data …Run Code Online (Sandbox Code Playgroud) php ×3
laravel ×2
mysql ×2
algolia ×1
eloquent ×1
laravel-5.2 ×1
laravel-5.3 ×1
laravel-5.5 ×1
node.js ×1
redis ×1
socket.io ×1
websocket ×1