
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
- Delete records with relationship in laravel
- How to create projects method with belongstomany relationship in user model
- Create project table with model and migration
- How to add foreign key in laravel using migration
- How to generate .env file for laravel?
- Laravel 7 login error message not showing
- Get 30 days older records from table in laravel
- How to add dynamic page title in Laravel view
- Shorter syntax for whereHas with call back function in laravel
- How to create belongstomany relation using custom name on custom pivot table
- Get last week data in Laravel
- How to get route name on visit URL in laravel
- How to check data inserted or deleted in pivot after toggle method
- How to get file extension from input type file in laravel
- Validation errors for multiple forms on same page Laravel
- The use statement with non-compound name 'DB' has no effect
- How to print form data in laravel
- How to check column value of a record is null or not in laravel
- Return redirect laravel not working
- The POST method is not supported for this route. Supported methods: PUT.
- Generate random string lowercase in Laravel
- Laravel create table migration with model
- Get id of last inserted record in laravel
- First and last item of the array using foreach iteration in laravel blade
- Display message with session flash using bootstrap alert class in laravel