Skip to content

Commit

Permalink
Add some relationship seeds; pull relationships in people.show
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstauffer committed Dec 2, 2019
1 parent 19f207e commit ba789e5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 7 additions & 1 deletion app/Console/Commands/SeedSomeData.php
Expand Up @@ -75,7 +75,13 @@ public function handle(Session $client)
$cypher = "
MERGE (adam:Person {name:'Adam'})
MERGE (eve:Person {name:'Eve'})
MERGE (eve)-[:MARRIED_TO]->(adam)";
MERGE (cain:Person {name:'Cain'})
MERGE (abel:Person {name:'Abel'})
MERGE (eve)-[:MARRIED_TO]->(adam)
MERGE (cain)-[:CHILD_OF]->(adam)
MERGE (cain)-[:CHILD_OF]->(eve)
MERGE (abel)-[:CHILD_OF]->(adam)
MERGE (abel)-[:CHILD_OF]->(eve)";
$client->run($cypher);

// @todo handle relationships
Expand Down
20 changes: 14 additions & 6 deletions app/Http/Controllers/PeopleController.php
Expand Up @@ -5,6 +5,7 @@
use App\Person;
use GraphAware\Bolt\Protocol\V1\Session;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

class PeopleController extends Controller
{
Expand Down Expand Up @@ -49,16 +50,23 @@ public function store(Request $request)
*/
public function show(Person $person)
{
$person = app(Session::class)
->run("MATCH (p:Person {eloquentId:'" . $person->id . "'}) RETURN p")
->firstRecord();
$results = app(Session::class)
->run("MATCH (p:Person)-[]-(friends) WHERE p.eloquentId = \"{$person->id}\" RETURN p, friends")
->getRecords();

dd($person);
// @todo find all relationships to $person
$first = Arr::first($results);
$personKey = array_search('p', $first->keys());
$friendKey = array_search('friends', $first->keys());

$person = $first->values()[$personKey];

$friends = collect($results)->map(function ($result) use ($friendKey) {
return $result->values()[$friendKey];
})->toArray();

return view('people.show', [
'person' => $person,
'relationships' => ['@todo'],
'relationships' => $friends,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion resources/views/people/show.blade.php
Expand Up @@ -19,7 +19,7 @@
<div class="w-full p-6">
Relationships:<br>
@foreach ($relationships as $relationship)
&bull; @dd($relationship)
&bull; {{ $relationship->name }} @todo figure out how to show HOW they are related<br>
@endforeach
</div>
</div>
Expand Down

0 comments on commit ba789e5

Please sign in to comment.