PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, December 28, 2021

[FIXED] Basic routing generates a 404 in Laravel

 December 28, 2021     laravel, laravel-routing, mamp, url-routing     No comments   

Issue

I'm trying to use the Laravel framework in building my application. However, I'm getting stuck with routing.

Route

Route::get('ecatalogs', 
    array('as' => 'ecatalog_latest', 'uses' => 'ecatalogs@latest'));

Controller

class Catalogs_Controller extends Base_Controller
{
    public $restful = true;

    public function get_latest()
    {
        return "wohoooooo!";
    }
}

My localhost files are stored in /Users/ariefbayu/Sites/ and my Laravel application is stored in /Users/ariefbayu/Sites/ecatalog/. Inside this directory, I have an info.php file to confirm if my path settings are working, and they do. However, when I navigate to http://localhost/ecatalog/public/index.php/ecatalogs it always returns a 404 error. I know this is basic, but I don't know why this doesn't work.

FYI, I'm using a MAMP server, and I've set all source files' access permissions to 777 to test if this is a permission problem.


Solution

Route::get('ecatalogs', array('as'=>'ecatalog_latest', 'uses'=>'ecatalogs@latest'));

Notice the ecatalogs@latest pointer. This tells Laravel to call the get_latest() method on the Ecatalog_Controller.

And this is your controller Catalogs_Controller and function get_latest(). You need to call the get_latest() with this :

Route::get('ecatalogs', array('as'=>'ecatalog_latest', 'uses'=>'catalogs@latest'));


Answered By - Wahyu Kristianto
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing