Send post data from controller to view
Created at 06-Sep-2021 ,
By samar
Send post data from controller to view
In this article, we will see how to solve "Send post data from controller to view".
You can send post data from controller to view using return view() method. Before sending data to view you have to get the data from the post model using Post::all() method.-
Get all post from table using controller and return to view in laravel 8
--PATH app\Http\Controllers\<YourController>.php//Import post model after the namespace in laravel controller use App\Models\Post; //Method inside controller’s class to get all post public function index(){ $posts = Post::all(); return view('home', compact('posts')); }
Related Queries
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
- Composer create project laravel/laravel example app
- Laravel create table migration with model
- Best Practices for Error Handling in Production Server Code (example code)
- How to get the random value form a specific column in laravel ?
- Get content from web URL in laravel
- Send id with route Laravel
- How to Run CRON Job on LIVE SERVER on Cpanel in Laravel Project
- The openssl extension is required for SSL/TLS protection but is not available
- How to get last record from object collection in laravel
- How to create projects method with belongstomany relationship in user model
- Laravel csrf token mismatch for ajax POST Request
- How to get count of all records created at yesterday
- Get last week data in Laravel
- Order by multiple columns in Laravel
- Target class [admin] does not exist.
- How to pass data to route in laravel?
- External link not working in laravel blade
- Submit form without CSRF token in Laravel
- How to get all posts which contains comments in laravel
- How to pass variable from controller to model in Laravel
- How to display a specific word from a string in laravel
- Laravel route redirect not working
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- How to pass query string to url in laravel
- How to add background image to div using Tailwindcss, Vite in Laravel Environment