Question

I am using laravel 4. I have a table which displays data from "cars" table. I want to click at one of car's name and display all information about this vehicle in a new page. I have done this:

index.blade.php

@foreach ($cars as $car)
 <tr>                                   
   <td> 
   {{ HTML::link('/desc', $car->Description, array('id' => 'linkid'), true) }}</td>  
   {{ Form::open(array('action' => 'CarController@showDesc', $car->id)) }}
   {{ Form::hidden('id', $car->id) }}
   {{ Form::close() }}
   <td>
   {{ $car->License }}</td>     
   <td>{{ $car->Make }}</td>     
   <td>{{ $car->status }}</td>                                    
   </tr>                                                            
@endforeach 

CarController.php

public function index() {
        $cars = Car::all();
        return View::make('pages.index', compact('cars'));
    }

    public function showDesc() {
      $description = //here want to get name, year, color from "cars" where id = POST['id']
      return View::make('pages.description', compact('description'));
    }

//pages description is the new page which will display all information about that specific vehicle ,

routes.php

Route::resource('cars', 'CarController');
Route::post('desc', array('uses' => 'CarController@showDesc'));

The problem is that browser shows: This webpage not available

Was it helpful?

Solution

you are using Route::resource('cars', 'CarController'); and this will create restful routes to access your controller and in the car controller you should have functions like index(), show($id), destroy($id). To see what are the valid routes, run php artisan routes in your project directory. if you want to follow the restful pattern which is what you want to do I think by using a resource route. be sure you have the function show($id) in your CarController. the route to that function is cars/{$id} so in your view make a link to this route:

{{link_to_action('CarsController@show',  $car->Description, $car->id)}}

I hope this will fix the problem

OTHER TIPS

in your view you have a link to "/description" and in the routes.php file you don't have a route to that link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top