
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')); }
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
- Ignore Records where a field has NULL value in Laravel
- How to check if user has created any post or not in laravel
- Session Doesn't Work on Redirect
- 419 page expired error in Laravel
- How to create projects method with belongstomany relationship in user model
- How to insert value to additional columns in pivot table in laravel
- How to check find method executed successfully in laravel
- Get ids in array from users table
- How to get specific columns using with method in laravel Eloquent relationship
- How to customize pagination view in laravel
- Laravel save object to database
- Laravel create multiple records in Pivot table
- How to change default timestamp fields name in Laravel
- How to create pivot table in laravel using migration
- How to get id of next record in laravel
- Create model with migration and seeder
- How to Get records between two dates in Laravel
- Route [password.request] not defined
- Use of undefined constant laravel
- Get id of last inserted record in laravel
- Use withCount() to Calculate Child Relationship Records
- Laravel get count with where condition
- Retain selected value of select box in Laravel
- How to pass external link in laravel blade to anchor tag
- Class "App\Http\Controllers\Auth\Verified" not found