I'm trying to start a new project in Laravel 5, and I'm running into some routing issues. I used Laravel 4 before for something similar, but I'm new to laravel 5.
What I'm trying to do is create a demo application with an AngularJS frontend, and Laravel as a backend server and API for data. I have gulp build my frontend into laravel/public/app, so my structure looks like this:
laravel
- app/
- frontend-src/
- public/
-- app/
--- index.php
--- js/
--- css/
--- views/
I configured Laravel to look for views starting in public/app like this in laravel/config/view.php:
'paths' => array(__DIR__.'/../public/app'),
Then I configured my routes to load the Angular index page for '/' and a Route Group for my API calls like this:
Route::get('/', function () {
return view('index');
});
Route::group(array('prefix' => 'api'), function() {
Route::resource('projects', 'ProjectController');
});
I'm serving it in development by using the artisan server and running it with php artisan serve
- and this works fine. The index page loads, my Angular application is visible, and the homepage looks correct.
However, when I added a service call to GET /api/projects in the home page, the server responds with a 500 error
GET http://localhost:8000/api/projects 500 (Internal Server Error)
At first I thought I named something wrong or the routes were not setup, so I ran the command php atisan route:list - but the routes look fine:
+--------+----------+------------------------------+----------------------+------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------------+----------------------+------------------------------------------------+------------+
| | GET|HEAD | / | | Closure | |
| | GET|HEAD | api/projects | api.projects.index | App\Http\Controllers\ProjectController@index | |
| | POST | api/projects | api.projects.store | App\Http\Controllers\ProjectController@store | |
| | GET|HEAD | api/projects/create | api.projects.create | App\Http\Controllers\ProjectController@create | |
| | DELETE | api/projects/{projects} | api.projects.destroy | App\Http\Controllers\ProjectController@destroy | |
| | PATCH | api/projects/{projects} | | App\Http\Controllers\ProjectController@update | |
| | GET|HEAD | api/projects/{projects} | api.projects.show | App\Http\Controllers\ProjectController@show | |
| | PUT | api/projects/{projects} | api.projects.update | App\Http\Controllers\ProjectController@update | |
| | GET|HEAD | api/projects/{projects}/edit | api.projects.edit | App\Http\Controllers\ProjectController@edit | |
+--------+----------+------------------------------+----------------------+------------------------------------------------+------------+
In the ProjectController, the index method is only one line:
return Response::json(array('success' => true));
Does anyone see what I'm missing, or what my /api routes would not not working? Thanks for your time, all!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1PJVKgk
via IFTTT
Aucun commentaire:
Enregistrer un commentaire