
How to send ID to another page in Laravel
Created at 11-Oct-2021 ,
By samar
How to send ID to another page in Laravel
In this article, we will see how to solve "How to send ID to another page in Laravel".
You can send an ID (variable value) to another page in Laravel using the route method in the anchor tag in the view file by passing the variable to it. You have to just pass data from route to controller and after controller to another view page.-
Pass variable (id) to another page as route parameter via controller in Laravel
//resources\views\welcome.blade.php @php $ID = 1; @endphp <a href="{{ route('id.detail', ['id'=>$ID]) }}"> Get id value in another view </a> //routes\web.php Route::get('get-id/{id}', [HomeController::class, 'getUserDetail'])->name('id.detail'); //app\Http\Controllers\HomeController.php public function getUserDetail($id){ return view('home')->with(['id'=> $id]); } //resources\views\home.blade.php <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- Bootstrap CSS --> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> <title>Home page !</title> </head> <body> <h1> {{ $id }} </h1> </body> </html>
Generated URL:
http://localhost:8000/get-id/1
Output:
1
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to get images from AWS s3 and display in Laravel blade
- The Pusher library requires the PHP cURL module. Please ensure it is installed
- On delete set foreign id column value null using migration in laravel 8
- Datetime field in Laravel migration
- Display message with session flash using bootstrap alert class in laravel
- Submit form without CSRF token in Laravel
- Property [user] does not exist on this collection instance
- How to decrypt laravel password
- How to get only time from created_at in laravel
- How to start websocket server in laravel
- Define variable and use in Laravel controller method
- Pagination in laravel
- How to create new user without form submission in laravel
- How to create project_user pivot table in laravel
- Trying to access array offset on value of type null error in laravel
- How to add class to tr in table using foreach in laravel
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- How to customize pagination view in laravel
- Pass value from controller to model in laravel
- How to pass external link in laravel blade to anchor tag
- Get products with number of orders in Laravel
- How to get user information using hootlex/laravel-friendships package in laravel
- Trying to get property 'title' of non-object
- How to print form data in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists