3

I am new in Laravel. I am trying to create a new page named as "contact". But i am getting a Object not found error when i am trying to access the contact page

URL: project-name/contact

please help me

---routes file

<?php

Route::get('/','WelcomeController@index');
Route::get('contact','WelcomeController@contact');

Route::group(['middleware' => ['web']], function () {
    //
});

--- Welcome controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class WelcomeController extends Controller
{
    public function index(){
        return view('welcome');
    }

    public function contact(){
        return 'Contact page goes here...';
    }
}
Anoop T U
  • 115
  • 13
  • please check your htaccess file once. http://laravel.io/forum/01-20-2015-object-not-found-error-again – Deep Kakkar Mar 09 '16 at 07:05
  • Do your other pages work? Did you point apache to laravel_root/public directory, not just to laravel_root? – Alexey Mezenin Mar 09 '16 at 07:09
  • @DeepKakkar i have updated my htaccess with the code showing on the URL mentioned in your comment. But still i am getting the same error. – Anoop T U Mar 09 '16 at 07:12
  • @AlexeyMezenin. You are right. I didn't. I can access the page on the URL my-website/public/contact. – Anoop T U Mar 09 '16 at 07:13

2 Answers2

1

Set your home directory to the public to make things work.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • Can you help me to do this? to set home directory to public – Anoop T U Mar 09 '16 at 07:20
  • It depends on what web server do you use: apache/nginx, or you use WAMP, MAMP, OpenServer, Homestead etc. – Alexey Mezenin Mar 09 '16 at 07:24
  • I found the solution here--> http://stackoverflow.com/questions/19923091/avoid-public-folder-of-laravel-and-open-directly-the-root-in-web-server. I think this will be helpful for beginners like me. Thanks All – Anoop T U Mar 09 '16 at 07:25
  • That solution works, but you're risking to get a lot of problems like strange 404/500 errors during development, especially if you're newbie who using tutorials to learn. I think the only good solution for newbies is to use standard Laravel approach to setup environment. – Alexey Mezenin Mar 09 '16 at 07:29
  • Do you have any standard solution to suggest for this issue? – Anoop T U Mar 09 '16 at 07:33
  • The only good way is to setup your root directory to a `public`. Please click link you posted above and look at another answer by `fideloper` (who has just 6 upvotes). That's the standard solution. – Alexey Mezenin Mar 09 '16 at 07:37
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/105769/discussion-between-anoop-and-alexey-mezenin). – Anoop T U Mar 09 '16 at 07:47
0

Exchange the route. like this:
Route::get('contact','WelcomeController@contact');
Route::get('/','WelcomeController@index');

darkvirus24
  • 109
  • 2
  • 9