John Clarke
John Clarke

Reputation: 13

How to set up dynamic page url's in laravel

I'm making a website (online course taking app) using Laravel 4.2.

I set up the route at /library to list my all course.

What I'm tying to do now is redirecting the user when it clicks on any course name on the url like /library/course/coursename But I'm unable to do so.

I figured out a bit like

<?php

class LibraryController extends BaseController {


    public function getIndex()
    {
        return View::make('library');
    }



    public function getCourse($list){
        return $list;
    }

}

Upvotes: 0

Views: 370

Answers (1)

Grald
Grald

Reputation: 464

#In your routes.php:

    Route::post('library/course/{coursenames?}', array('as' =>    'post.coursename', 'uses' => 'LibraryController@postCoursename'));

#In your LibraryController.php:
    private function postCoursename($coursenames=null){
     $coursenames = array('bscs'=>'CS','bsit'=>,'IT');
     return View::make('library',compact('coursenames'));
     }
#In your blade views:
    @foreach($coursenames as $coursename)
    {{link_to_route('post.coursename',$coursename->bscs, [$coursename->bscs])}}
    {{link_to_route('post.coursename',$coursename->bsit, [$coursename->bsit])}}
    @endforeach

then check your view there was a links called:

[CS][1]
[IT][2]
then try to click the link and see the address url if it's changing.

  [1]: http://localhost/library/course/cs
  [2]: http://localhost/library/course/it

Upvotes: 2

Related Questions