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

Tuesday, January 4, 2022

[FIXED] Route does not find variable

 January 04, 2022     laravel, laravel-5     No comments   

Issue

i need to pass a variable $empresa to my route, but it can't find it.

find the route only as ( / )

Route::get('/', function() {
    if (Auth::guest()) {
        return redirect('/home');
    }
    else {
    
        $empresa = Auth::user()->empresa;
                    return redirect('/' .$empresa);
    }    
});

I only get this problem in web.php file help please


Solution

That' likely because you haven't declared a controller for the route / with parameter.

It's not always a best practice to declare a controller right in route file like this. But let's ignore that and continue.

Route::get('/', function() {
    if (Auth::guest()) {
    return redirect('/home');
}
    else {

      $empresa = Auth::user()->empresa;
                return redirect('/')->with(['empress' => $empresa]);
    }
});

Just make sure that you have declared a controller for /{empress} route. Something like this:

Route::get('/{empress}', 'YourController@methodName');


Answered By - Huy Phạm
  • 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