
Return view from route Laravel
You can return to view from route in Laravel. You have to create a web route with the call back function and use return view('home') in callback to return to view file or you can also use Route::view() method to return to view file in Laravel
-
Return view from route using return::view() method
//routes\web.php //Route definition Route::get('/home', function () { return view('home'); }); //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 !</title> </head> <body> <h1> Home page </h1> </body> </html>
0You can return to view file in laravel using return view() method in callback function while defining the web route in php
-
Return data to view using route::view method in Laravel
//routes\web.php Route::view('/welcome', 'welcome', ['id' => 1]); //resources\views\welcome.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>Welcome !</title> </head> <body> <h1> {{ $id }} </h1> </body> </html>
0You can use Route::view() method in web.php file while defining the web route and return to view (passed as second agruments to route::view method) without any callback function with data which is passed as third arguments to route definition.
Random Code Snippet Queries: Laravel
- Call to undefined method App\Models\User::follow()
- Run artisan command to generate key in laravel
- How to add a key value pair to existing array in laravel
- How to insert value to additional columns in pivot table in laravel
- Permanently delete a record in laravel
- Composer\Exception\NoSslException
- Symlink(): No such file or directory
- Remove several global scope from query
- Laravel hasmany select not working
- Credit card validation in laravel
- How to display 1 day ago in comments in laravel view
- How to get all posts which contains comments in laravel
- How to create belongstomany relation using custom name on custom pivot table
- How to display a specific word from a string in laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Laravel route redirect not working
- How to get route method name in Laravel
- Php artisan make model, factory, migration and controller in single command
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- Json encode method in laravel
- Fatal error: Uncaught Error: Class "Illuminate\Foundation\Application" not found
- How to use more than one query scope in Laravel
- Send post data from controller to view
- Laravel csrf token mismatch for ajax POST Request
- How to add script on specific view file in laravel while extending layout