0

Let's say I have a folder like this

  resources/views
       paths
          path1
             index.blade.php
             registration.blade.php
          path2
             index.blade.php
             registration.blade.php

And my route

   Route::get('/paths/{$path}, function(){
       return view('paths/{$path}/index);
   });

This doesnt work if I do this

 localhost.com/paths/path1

Any Idea how make it work? Doing this in controller is more preferred.

Ok I already fixed that in closure before train_fox answered. I preferred that in controller

public function index(Request $request, $path)
{
 $paths = [
        'CD1',
        'CD2',
        'CD3',
    ];
    foreach($paths as $path){
        if($path === request()->segment()){
            return $this->paths = $path;
        }
    }
   return view('paths/'.$this->path.'/index');
}

Any ideas?

1
  • 1
    Did you read your code properly? Commented Mar 14, 2017 at 6:06

2 Answers 2

1

Your route should be:

 Route::get('/paths/{path}', function($path){

   return view("paths/{$path}/index");
 });

Hope it will serve your purpose.

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

Comments

0

You forgot to pass variable to closure:

Route::get('/paths/{$path}, function($path){
   return view('paths/{$path}/index);
});

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.