Charges well with the laravel server but does not load with xampp

1

I'm doing some routes in Laravel when I load these routes with the Laravel server works well for me http://127.0.0.1:8000/products

Answer me the return of the driver that is 'good night'

the route is

Route::resource('products','ProductController');

and the view:

Route::get('/' , function(){

    return view('app');
});

Controller:

class ProductController extends Controller
{

    public function index()
    {
        return 'buenas noches';
    } 

 } 

In app this:

<body>
    <div class="container">

        @yield('content')
        <a href="{{ route('products.index') }}">info</a>
    </div>

    <script src="{{ asset('js/app.js') }}" ></script>
    </body>

but when I use it with xampp:

http://home.pro/laravel/tienda1/public/products

Show me:

  

Sorry, the page you are looking for could not be found.

    
asked by William T 08.04.2018 в 07:28
source

2 answers

1

I'll tell you a couple of things about your code.

  • If you already have a resource controller, which will control the request to show that specific view through the index method; The only thing you should have in your code is:
  • The routes.js file

    Route::resource('/products', 'ProductoController');
    

    On your controller, where hello is the name of the view but you can put the one you want

    public function index() 
        {
            return view('hola');
        }
    

    And finally the URL that you should work on your XAMPP is the following

      

    link

    Unless you have configured a specific server, your URL must be composed of:

  • localhost = > Well, point to a resource from your own PC
  • tests = > this is the name of the whole project, replace it with the one you put in yours
  • public = > there is the frontend controller then processes the requests that arrive at the Framework
  • products = > is the URL that I declared as an access point in my routes.php file
  • WHAT I DO NOT SEE NEEDED

    Unless you explain to us what use you give, the following fragment of code I see it more; that is, I should not go

    Route::get('/' , function(){
    
        return view('app');
    });
    

    AN ALTERNATIVE MORE

    If for any reason that view you are trying to return does not have dynamic content, that is, interacting with BD, you can avoid the controller part and use the utility from Laravel 5.6; as follows

    Route::view('/productos','hola');
    
      

    Where you first place the URL that must respond and second the name of   the view you are going to invoke; but EYE is only for content views   static

        
    answered by 08.04.2018 / 14:54
    source
    1

    The problem is that the laravel server starts running from the public folder, which when trying to access the root, it does so in public/ and in xampp, the root in htdocs the solution is to create a local domain that points to http://home.pro/laravel/tienda1/public/

  • Go to file C:\Windows\System32\drivers\etc\host
  • Add your host to the end of the file like 127.0.0.1 tienda1.com
  • Save the file, you will need administrator permission. I recommend editing it with notepad ++
  • Now go to file C:\xampp\apache\conf\extra\httpd-vhosts.conf
  • Edit the file and direct your host to your project folder

    <VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot "C:\xampp\htdocs\laravel\tienda1\public"
        ServerName tienda1.com
        ErrorLog "logs/tienda1.com-error.log"
        CustomLog "logs/tienda1.com-access.log" common
    </VirtualHost>
    
  • this should work with

        
    answered by 08.04.2018 в 17:43