
How to pass two variables in HREF in laravel
You can pass two variables to anchor tag (HREF) in Laravel. You can call the url() helper function or you can call the route method with multiple arguments in Laravel view to pass the variable values to anchor tag in Laravel.
-
Pass multiple variables to anchor tag (href) using url() helper in laravel view
--PATH resources\views\<home>.blade.php<a href="{{ url('user/'.$user->id . '/'.$user->name) }}"> Get user detail </a>
0Output:
user/1/summer
You can pass the multiple variable to url in laravel using url() helper method. To pass the value using $user->id and $user->name variable to URL you have to define web route and get the user details using controller's method. You can get user details as below.
Route definition
use App\Http\Controllers\HomeController; Route::get('user/{id}/{name}', [HomeController::class, 'getUserDetail']);
Controller's method code to get the user details to pass the value to anchor tag
$user = User::findOrFail(1); return view('home')->with('user', $user);
You have to get the data (user details) and return to view name on which you want to return data.
Random Code Snippet Queries: Laravel
- Call to a member function pluck() on array
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- How to get list of all views file in laravel
- Store logged in user details in session and display in view in laravel
- Laravel create multiple records in Pivot table
- Laravel append URI in route
- Return redirect laravel not working
- Get previous date data in laravel
- Route group with URI prefix using middleware and route name prefixes
- How to get laravel errors folder in views directory in laravel
- How to get route name on visit URL in laravel
- Laravel delete all rows older than 30 days
- How to change default timestamp fields name in Laravel
- Get the post details if it has at least one comment in comments table
- How to include header file in laravel
- Get latest record by created at in Laravel
- How to restore deleted records in laravel
- Permanently delete a record in laravel
- How to call controller function from view in Laravel
- Calculate age from date of birth in Laravel
- SQLSTATE[23000]: Integrity constraint violation: 1022 Can't write; duplicate key in table
- Json encode method in laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Use withCount() to Calculate Child Relationship Records
- Convert input array to comma-separated string in laravel controller