1

I need to fetch the data from database and display it view . This is my web.php

Route::get('/businesscard/{name}',  function ($name) {
    
    
//$username= App\users::where('username', $name);


$username=DB::table('users')->select('*')
                     ->where('username', '=', $name)
                    // ->groupBy('status')
                     ->get();
   
    return view('auth.pro')->with(['username' => $username]);
   
   
   
     return array(
       'name' => $name
       );
       
       
       
});

If the user enters domain.com/businesscard/username I need to fetch the data for the username and display it in view .It is working.But I need to remove businesscard .User need to enter domain.com/username. I have tried the below code.

Route::get('/{name}',  function ($name) {
    
    
//$username= App\users::where('username', $name);


$username=DB::table('users')->select('*')
                     ->where('username', '=', $name)
                    // ->groupBy('status')
                     ->get();
   
    return view('auth.pro')->with(['username' => $username]);
   
   
   
     return array(
       'name' => $name
       );
       
       
       
});

If there is data it is working .but other pages are not working like login and register .Users are entering their username in registration .

2
  • /{name} That means, /login, /register wont work. Commented Jul 12, 2020 at 10:59
  • check my answer it will helpful for you. If it's helpful then give a upvote and accept my answer.Thanks Commented Jul 12, 2020 at 11:08

2 Answers 2

1

The order of your route matters. See order of route declarations in laravel package

So the /{name} should be registered as the last route to avoid matching for other routes.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks .I have changed the route order . It is working .
Please also mark it as the answer for others to find it.
0

/{name} it means / with any value. If you try /login or /register.Then your logic is confused with this so that other pages are not working. Best way to develop as you expect like first one.

Another thing in your code there is two return second one is not doing anything. After the first one it return to view so second one unused. remove that return as well.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.