1. Go to this page and download the library: Download scriptle/laragraph library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\GraphQL\Queries;
use Scriptle\Laragraph\Type;
use App\Models\User;
...
#[Type('V1Query', 'Root queries for v1')]
class V1Query {
#[Field('users', '[User]!', 'Lists all users.')]
public function users() {
return User::all();
}
// More on this later
#[Field('lookupUser("User ID" id: String, "User Email" email: String)', 'User', 'Look up a user by ID or email.')]
public function lookupUser($args) {
// More on this later
return User::where($args)->first();
}
}
namespace App\Models\User;
use Scriptle\Laragraph\Type;
...
#[Type]
class User extends Authenticatable {
...
}
namespace App\Models\User;
use Scriptle\Laragraph\Type;
use Scriptle\Laragraph\Field;
...
#[
Type('User', 'A user in the database.'),
Field('id', 'String!', 'User ID'),
Field('first_name', 'String!', "User's first name"),
Field('last_name', 'String!', "User's last name"),
Field('roles', '[Role]!', 'Array of user roles'),
]
class User extends Authenticatable {
...
}
namespace App\Models\User;
use Scriptle\Laragraph\Type;
use Scriptle\Laragraph\Field;
...
#[
Type('User', 'A user in the database.'),
Field('id', 'String!', 'User ID'),
Field('first_name', 'String!', "User's first name"),
Field('last_name', 'String!', "User's last name"),
Field('roles', '[Role]!', 'Array of user roles'),
]
class User extends Authenticatable {
...
public function resolveLastNameField()
{
return strtoupper($this->attributes['last_name']);
}
}
namespace App\Models\User;
use Scriptle\Laragraph\Type;
use Scriptle\Laragraph\Field;
use Scriptle\Laragraph\ResolvesFor;
...
#[
Type('User', 'A user in the database.'),
Field('id', 'String!', 'User ID'),
Field('first_name', 'String!', "User's first name"),
Field('last_name', 'String!', "User's last name"),
Field('roles', '[Role]!', 'Array of user roles'),
]
class User extends Authenticatable {
...
#[ResolvesFor('last_name')]
public function getLastNameAttribute()
{
return strtoupper($this->attributes['last_name']);
}
}
namespace App\Models\User;
use Scriptle\Laragraph\Type;
use Scriptle\Laragraph\Field;
...
#[
Type('User', 'A user in the database.'),
Field('id', 'String!', 'User ID'),
Field('first_name', 'String!', "User's first name"),
Field('roles', '[Role]!', 'Array of user roles'),
]
class User extends Authenticatable {
...
#[Field('last_name', 'String!', "User's last name")]
public function anything()
{
return strtoupper($this->attributes['last_name']);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.