Link to home
Start Free TrialLog in
Avatar of adra750
adra750

asked on

Laravel 5: problem with view

Hello,

I created a navbar menu where you click on profile and you get to profile based on your username, example, if your username is: Anderson. when you click on profile, it takes you to web.app/anderson

but the issue is this, when I log in, laravel show me a link of : http://web.app/respond.min.js that takes me to profile page instead of http://web.app/home home page

That happens because of this route:

 
Route::get('{username}', 'ProfileController@index');

Open in new window


When i change the {username} to 'profile', everything works normal but it doesn't achieve my needs which is to redirect to http://site/username

any idea, did i make any mistake in the syntax?
Avatar of Scott Madeira
Scott Madeira
Flag of United States of America image

Can you post your routes file as well as the navbar code and at least the index method of the ProfileController?
Avatar of adra750
adra750

ASKER

Routes:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

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

Route::get('/Home', 'HomeController@index');

Route::get('/{username}', 'ProfileController@index');

Route::controllers([
	'auth' => 'Auth\AuthController',
	'password' => 'Auth\PasswordController',
]);

Open in new window


ProfileController.php

<?php namespace App\Http\Controllers;

class ProfileController extends Controller {

	/*
	|--------------------------------------------------------------------------
	| Home Controller
	|--------------------------------------------------------------------------
	|
	| This controller renders your application's "dashboard" for users that
	| are authenticated. Of course, you are free to change or remove the
	| controller as you wish. It is just here to get your app started!
	|
	*/

	/**
	 * Create a new controller instance.
	 *
	 * @return void
	 */
	public function __construct()
	{
		$this->middleware('auth');
	}

	/**
	 * Show the application dashboard to the user.
	 *
	 * @return Response
	 */
	public function index()
	{
		return view('profile');
	}

}

Open in new window


profile.blade.php

@extends('header')

@section('content')

<div id="profilepage"> Cover image 
<div class="container">
		<img src="/img/avatar.png" class="img-circle" width="120" height="120">
  </div>
  <strong><div class="profileusername">{{ Auth::user()->name}}</strong></div>
</div>
<div id="profilemenu">
	<div class="navmenupp">
	<ul>
	<li><a href="{{ url('#') }}">Text1</a></li>
	<li><a href="{{ url('#') }}">Text2</a></li>
	<li><a href="{{ url('#') }}">Text3</a></li>
	<li><a href="{{ url('#') }}">Text4</a></li>
	
	</ul>
	</div>

</div> 

@yield('content')
@endsection

Open in new window

What is the desired outcome of going to http://web.app/anderson? 

Where did the respond.min.js come from?  I don't see how that could be built into a link.

Also, in profile.blade.php why are you yielding a section called content inside a section called content?  That seems like it could be a problem.
From what you posted, the only way to get to the Home controller is to use a url of web.app/Home.

The only way you will get to the WelcomeController is by going to http://web.app

All other URLs should go to ProfileController because it takes any text after web.app/ and uses that as a variable that could be an input to the index method.

So, I'd like to better understand what you are trying to do.
Avatar of adra750

ASKER

your conclusion is right however the issue i'm having is, when i login, the url goes to web.app/respond.min.js why? it should take me to /Home
Avatar of adra750

ASKER

this syntax is incorrect:

Route::get('/{username}', 'ProfileController@index');

Open in new window


because whatever i type after the "/" it works and it shows me the profile page without a problem so web.app/gfjhdfkjghdfgjkh works fine.

I need to add something so it can verify the user is really the one who is getting to his profile

I tried username:users as in Service->Registrar but it didn't work
Avatar of adra750

ASKER

Any idea
Can you zip up your app folder and upload it?  I should be able to look at it today...
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.