Question

So sorry to bother y'all, but I was wondering if anyone could help me. I'm having a wee bit of a problem with my code in Laravel, being used to working from scratch rather than with frameworks. I made use of the Laravel Bootstrap Starter Site and I'm trying to add additional pages, but the routing isn't exactly co-operating. It's rather frustrating.

The Controller: app/controller/community/CommunityController.php

<?php
    class CommunityController extends BaseController {
        public function index() {
            return View::make('community.index');
        }
    }
?>

The View

@extends('site.layouts.default')


{{-- Content --}}
@section('content')
@foreach ($posts as $post)
<div>
    I'm just going to put this here... 

</div>

@endforeach

{{ $posts->links() }}

@stop

And finally, last but not least, my routes.

Route::get('community', array(
  'uses' => 'CommunityController@index',
  'as' => 'community.index'
));

Now, I have this nagging feeling that I'm missing something rather small, but for the life of me I can't figure it out. If anyone would be so kind to explain what I'm doing wrong, I'd appreciate it. Especially since I can prevent this kind of problem happening in the future as well.

With friendly regards, User who still hasn't picked out a good name

Edit: Sorry I forgot to mention this. I removed public, so I don't know if that influences anything. If it does, again, sorry for forgetting to mention this in the beginning.

Was it helpful?

Solution

you can try to bind the whole route to the controller, using

Route::controller('community', 'CommunityController');

then in your controller you have to prefix the controller methods with HTTP verbs. Your index() method will be

public function getIndex() {
        return View::make('community.index');
    }

OTHER TIPS

Just fire composer dump-autoload in root of your project folder from terminal / console.

It'll load your controller which is in subfolder.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top