Laravel 5.1 and $ Http angularjs

0

I'm trying to access the 'App \ Http \ Controllers \ ReportController @ store' URL from la http, but the route does not load or can not be found, with php artisan route: list it appears to me that it is the route ... How can I access that route or how can I access any route as long as it helps me download data from bd?

Angular Code

app.controller('DatosController', function ($scope,$http)
{
$scope.consultDate = function ()
{
    $http({
        method: 'GET',
        url: 'App\Http\Controllers\ReportController@store'
        })
    .then(function ( { data })
    {
        // hacer algo con el array de datos
    },
    function (response)
    {
        // callback de error
        console.error(response.statusText);
    });
};

});

Laravel Code

public function store(Request $request)
{
    return "Algo";
}
    
asked by 01.02.2017 в 16:55
source

2 answers

0

I think that Laravel's actions, like the ones in your code, are not recognized as valid URLs, so you can not use them in AngularJs.

$http({
    method: 'GET',
    url: 'App\Http\Controllers\ReportController@store'
}).then(function(response) {
    // ...
});

You will have to replace it with the correct url. Something of the% /report/store .

On the other hand, I see that you are trying to access the store method, which in the Laravel Resource controllers is accessed with the POST method instead of GET . Your code would look something like this:

$http({
    method: 'POST',
    url: '/report'
}).then(function(response) {
    // ...
});
    
answered by 09.02.2017 / 14:10
source
0

From what I see in the code, you have slash, instead of, backslash.

    url: 'App/Http/Controllers/ReportController@store'
    
answered by 06.02.2017 в 05:43