Passing A Parameter To A Route And Controller In Laravel 6
I am quite new in Laravel so please help. I am trying to pass a parameter from a blade file to a route which then passes the parameter to the controller. This is a resource controller. I've tried the URL() way of calling, I've tried making the route callback function do the same thing but for some reason, the ID was never passed to the function but it appears in my address bar. So it never got to the dd($id) part of the code. I also tried creating a new model and controller just for this but it also did not seem to work.
What am I missing here?
This is my view code:
<td><a target="_blank" rel="nofollow noreferrer" href="{{ route('/cars/'. $car->id)}}" class="btn btn-primary">Rent</a></td>
This is my route:
Route::get('cars/{id}', '[email protected]');
This is the controller code:
public function updateUserId($id)
{
dd($id);
$user_id = Auth::id();
dd($user_id);
Car::whereId($id)->update($user_id);
}
Answer
Just use this {{ route('/cars/', $car->id) }}
OR {{ route('cars', $car->id) }}
and don't concatenate this as a string because route method accept a second parameter for this case.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms