0

I am a noob with laravel just picked it up today, what seems to be an easy task that looks lovable has caused a headache.

I am following a tutorial from Jeffery Way, and we seeded the database, the next step is to create a controller and get the resource. I generated the necessary files, then followed these basic steps.

The database table is 'players'

Step 1.

//Here is the index() function inside my PlayersController.php
class PlayersController extends \BaseController {
    public function index()
    {
        return Player::all();
    }
}

Step 2.

//Inside the app/models/ directory I create a file called Player.php
//Here is the code inside Player.php
class Player extends Eloquent {
    protected $table = 'players' // I tried without the protect aswell
}

Step 3.

//Finially a route
Route::resource('players', 'PlayersController');

Route::get('/', function()
{
    return View::make('hello');
});

For extra measure I also ran composer dump-autoload in the command line, inside the root directory of my laravel project.

Then now I wasnt told which directory the route would be in, since it's an index function I assumed it's inside the root, so I have tried several url's

http://localhost/basketball-app-framework/public/players http://localhost/basketball-app-framework/players

This last one would obviously only work if I pointed localhost to the public directory, I did do that however, still a no go. I am confused as ever.

http://localhost/players

I have tried a bunch other url's but those only are the ones that make sense, and the ones I am pretty sure should be working.

It blows I have to do some digging to figure out this simple mistake I am sure I am making, but whatever it takes to understand why I cant fetch that data from my database.

Michael Joseph Aubry
  • 12,282
  • 16
  • 70
  • 135

1 Answers1

0

Okay looks like it was a mod_rewrite, and AllowOverride All issue inside the http.conf file.

I figured out some better keywords that applied to my issued and came across this Laravel 4 simple route not working using mod_rewrite, and .htaccess

As of now the simple users route that the documentation provides works. http://localhost/basketball-app-framework/public/users returns Users!.

So its nice to have this figured out, I still feel confused though haha.

Community
  • 1
  • 1
Michael Joseph Aubry
  • 12,282
  • 16
  • 70
  • 135
  • For your URL: http://localhost/basketball-app-framework/public/users It looks like your virtual host isn't set up correctly. The DocumentRoot should be pointing to the "/public" directory, you should not have to add that to the URL yourself. I would go back and check your virtual host config to make sure that the DocumentRoot is set to the right path. – berrberr Jan 08 '14 at 03:24
  • Oh I get what you that means now lol. So I should set all my other projects into that directory? – Michael Joseph Aubry Jan 08 '14 at 04:14
  • 1
    No, what you should do is for each project you are hosting on your machine create a new Virtual Host. I recommend this approach because it centralizes all of the settings for each website in one spot (the apache vhost config files). The simpler approach is just to put a new folder in your www root for each project you are working on, but I like the virtual host + change the port for each project method. For Laravel though, the important thing to remember is to always map to the /public directory - if you look at that directory you will notice that that is where the "index.php" file is – berrberr Jan 08 '14 at 14:25