/** * Return all the rows. * * @return \Illuminate\Support\Collection */ public function get() { $url = $this->table; if ($this->parent) { $url = $this->parent->getTable() . '/' . $this->parent->id . '/' . $this->table; } $response = $this->request('get', $url, $this->parameters); return collect($response)->map(function ($row) { return $this->newInstance($row, $exists = true); }); }
public function posts() { return $this->hasResource(Post::class); } } class Post extends Model { public function category() { return $this->hasResource(Category::class); } } $client = new Client(['base_uri' => 'http://headless.app/api/']); Model::setHttpClient($client); $token = Model::authenticate(['email' => '*****@*****.**', 'password' => 'password']); Model::setDefault('access_token', $token); // // $response = $client->get('posts', [ // 'query' => [ // 'limit' => 1 // ] // ]); // echo $response->getBody(); // exit; // // $session = new Session; // // $session->login([ // 'email' => '*****@*****.**', // 'password' => 'password', // ]);
/** * Set the guzzle instance. */ private function mockGuzzle($callback) { $guzzle = Mockery::mock(GuzzleHttp::class); $callback($guzzle); Model::setHttpClient($guzzle); }