Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to use RESTful controller. Here is my Route.php:

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

Here is my TestController.php

<?php
class TestController extends BaseController {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
            return View::make('test.home');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function create()
    {
            //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
            //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
            //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
            //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id)
    {
            //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
            //
    }
}

My app route is localhost/Test/public/ and it shows "You have arrived" message. But when I tried localhost/Test/public/test It gives me "SymfonyComponentHttpKernelExceptionNotFoundHttpException"

Here is my log:

[2014-05-11 14:29:59] production.ERROR: NotFoundHttpException Route: `http://localhost/Test/public/test` [] []
[2014-05-11 14:29:59] production.ERROR: exception 'SymfonyComponentHttpKernelExceptionNotFoundHttpException' in C:wampwwwestootstrapcompiled.php:5289
Stack trace:
#0 C:wampwwwestootstrapcompiled.php(4663): IlluminateRoutingRouteCollection->match(Object(IlluminateHttpRequest))
#1 C:wampwwwestootstrapcompiled.php(4651): IlluminateRoutingRouter->findRoute(Object(IlluminateHttpRequest))
#2 C:wampwwwestootstrapcompiled.php(4643): IlluminateRoutingRouter->dispatchToRoute(Object(IlluminateHttpRequest))
#3 C:wampwwwestootstrapcompiled.php(698): IlluminateRoutingRouter->dispatch(Object(IlluminateHttpRequest))
#4 C:wampwwwestootstrapcompiled.php(679): IlluminateFoundationApplication->dispatch(Object(IlluminateHttpRequest))
#5 C:wampwwwestootstrapcompiled.php(1136): IlluminateFoundationApplication->handle(Object(IlluminateHttpRequest), 1, true)
#6 C:wampwwwestootstrapcompiled.php(7218): IlluminateHttpFrameGuard->handle(Object(IlluminateHttpRequest), 1, true)
#7 C:wampwwwestootstrapcompiled.php(7815): IlluminateSessionMiddleware->handle(Object(IlluminateHttpRequest), 1, true)
#8 C:wampwwwestootstrapcompiled.php(7762): IlluminateCookieQueue->handle(Object(IlluminateHttpRequest), 1, true)
#9 C:wampwwwestootstrapcompiled.php(10768): IlluminateCookieGuard->handle(Object(IlluminateHttpRequest), 1, true)
#10 C:wampwwwestootstrapcompiled.php(640): StackStackedHttpKernel->handle(Object(IlluminateHttpRequest))
#11 C:wampwwwestpublicindex.php(49): IlluminateFoundationApplication->run()
#12 {main} [] []

I know this question has been asked many times. I had gone through many relevant threads but just can not figure out the solution.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
250 views
Welcome To Ask or Share your Answers For Others

1 Answer

A NotFoundHttpException exception in Laravel always means that it was not able to find a router for a particular URL. And in your case this is probably a problem in your web server configuration, virtual host (site) configuratio, or .htaccess configuration.

Your public/.htaccess should look like this:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

As you can see there is a condition in the first line IfModule mod_rewrite.c, so if you don`t have mode_rewrite installed or enabled, all rewrite rules will fail and this

localhost/Test/public/

Will work fine, but not this:

localhost/Test/public/test

In other hand, this one should work too, because this is its raw form:

localhost/Test/public/index.php/test

Because Laravel needs it to be rewritten to work.

And note that you should not be using /public, your URLs should look like this:

localhost/Test/

This is another clue that your virtual host's document root is not properly configured or not pointing to /var/www/Test/public, or whatever path your application is in.

All this assuming you are using Apache 2.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...