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
- How to check record exist or not in relationship table
- Create user in Laravel using tinker
- Root composer.json requires php ^7.3 but your php version (8.0.0) does not satisfy that requirement
- How to delete record in Laravel with ajax
- Route [password.request] not defined
- Recursive function example code PHP Laravel
- How to pass two variables in HREF in laravel
- Get all users except the followings users in overtrue laravel-follow
- Get duplicate records in laravel
- Retain selected value of select box in Laravel
- How to get route method name in Laravel
- Laravel create default admin user
- Laravel specific table Migration
- Command to create MySQL Docker image and access the MySQL command-line interface (CLI) within a running Docker container
- Laravel 9 pagination with search filter
- Automatically remove records using Prunable trait in Laravel
- How to update record after save method in Laravel
- How to get the id of last record from collection object in laravel view
- Illuminate\Database\QueryException could not find driver
- Trying to get property 'title' of non-object
- Route prefix with auth middleware in laravel
- Get domain name in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1075 Incorrect table definition; there can be only one auto column and it must be defined as a key
- Update if exist else insert new record in laravel
- Drop foreign key column in Laravel using migration