mercredi 10 février 2016

Accessing Nested URL Using Blade in Laravel 5.1

I am trying to access a page using a nested url in Laravel 5.1 but I have reached a dead end. I would like to make a GET request with a parameter in the middle of the url. To be precise, cars/{cars}/edit. This is my code:

In the routes file

Route::resource('cars', 'carController');

In the cars controller file

class carController extends Controller
{

    public function index(){

       $cars = Car::all();
       return view('carshome', compact('cars'));
    }

    public function edit($id){  
        return 'Welcome:  '.$id.'page';
    }
}

In the carshome blade template file

@foreach ($cars as $car)
<tr>
    <td>{{ $car->name }}</td>
    <td>{{ $car->type }}</td>
    <td class="text-center">
        <a href = {{url('/cars',[$car->name])}}>
           <i class="fi-clipboard-pencil"></i>
        </a>
        <a href = {{url('/cars',[$car->name])}}>
           <i class="fi-x-circle"></i>
        </a>
    </td>
</tr>
@endforeach

In the car model file

class Car extends Model
{
    protected $fillable = [
        'name', 'type'
    ];
}

The helper function url can take parameters as part of the url. Am not sure how I can it to create the custom url. How can I access the url resource using blade?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire