jadjoubran / laravel5-angular-material-starter

Get started with Laravel 5.3 and AngularJS (material)
https://laravel-angular.readme.io/
MIT License
1.66k stars 400 forks source link

Calling an external API with Guzzle and passing data to Angular #404

Closed Banjerr closed 8 years ago

Banjerr commented 8 years ago

I've been trying to port a pure Laravel site/app over to this project and having a little trouble with some parts, likely due to my lack of knowledge.

In my Laravel controller

class HomeController extends Controller
{
    // home page junk
    public function getGit() {
      // use Guzzle to get GH info
      $client = new GuzzleHttp\Client();
      $res = $client->request('GET', 'https://api.github.com/user', [
          'auth' => ['/*USERNAME*/', '/*PASSWORD*/']
      ]);

      $gitBody = $res->getBody();

      return response()->json($gitBody, 200);
    }
}

in my angular component.js

class GetGitCommitsController{
    constructor(API, $log){
        'ngInject';

        this.API = API;
        this.$log = $log;

        this.gitStuff = this.API.all('git').getList().$object;
        $log.log(this.gitStuff);
    }

    $onInit(){

    }
}

and my routes.php

// Home Routes...
    $api->post('git', 'HomeController@getGit');

any advice? I'm geting 405 Method Not Allowed

flick36 commented 8 years ago

$api->post('git', 'HomeController@getGit');

should be a get method

Banjerr commented 8 years ago

@flick36 that did the trick; makes perfect sense that it would be a get now that you point that out. thanks for the help! really digging this project, btw @jadjoubran ! thanks for all the hard work