passing id to the route
I have a route in the view to direct me to edit a component, but when I pass the id it does not work. What would be the problem?
when I give dd($value->id), I get the return of the id
When I click on edit, I get a 400 error
@php
$site = request()->route('website')->slug;
$website = request()->route('website');
$page = request()->route('page');
$slug = $model->getRouteKey();
$components = $model->components;
@endphp
<div class="list-group">
@foreach( $components as $value)
<div class="form-group row">
<label class="col-sm-6 col-form-label">{{$value->order}} - {{ $value->component }}</label>
<div class="col-sm-6">
<a href="#" class="fa fa-angle-double-up btn btn-primary btn-sm"></a>
<a href="#" class="fa fa-angle-double-down btn btn-primary btn-sm"></a>
<a href="{{ route('website.pages.components.edit', [$website, $page, 'component' => $value->component]) }}"
class="btn btn-warning btn-sm">Editar</a>
<a href="" class="btn btn-danger btn-sm">Deletar</a>
</div>
</div>
@endforeach
<a class="btn btn-primary" href="{{ route('website.pages.components.create', [$site, $slug]) }}"> Adicionar
Componente </a>
</div>
The second parameter of the route function is used to send along parameters to named routes, e.g. an ID:
route('users.edit', ['id' => 5]); // /users/5/edit
- With that explanation in mind, are you using the function correctly for your use-case?
- When you click the link, what URL do you get redirected to? Does it look malformed or not according to your spec?
- If the URL you're redirected to is fine, is the appropriate controller and its function being triggered?
In the "web.php" routes file:
Route::get('component/{id}/edit', function ($id) {
// ...
})->name('component.edit');
In your blade view file:
<a href="{{ route('components.edit', [ 'id' => $component->id]) }}"
Please post the route in the "web.php" routes file of your application for more info.
Route::group([
'as' => 'pages.',
'prefix' => 'pages/{page}',
'middleware' => 'managercontext:website_page'
], function() {
Route::resource('components', 'Website\PageContentComponentsController', [
'only' => ['show', 'create', 'store', 'edit', 'update', 'destroy']
]);
});
You'll probably need something like this:
<a href="{{ route(
'website.pages.components.edit',
[
'website' => $website,
'page' => $page,
'component' => $value
]
)}}"
class="btn btn-warning btn-sm"
>Editar</a>
Please run "php artisan route:list" and paste the output for the named route (the "website.pages.components.edit" named route).
@ROMULO27 - I don't see any mention of "website" in the code provided.
Please run "php artisan route:list" and paste the output for the named route (the "website.pages.components.edit" named route).
and also look in your browser source code view and see what what actual route is being generated
(or look in the addressbar when you get the 400 error)
Please or to participate in this conversation.