
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
- Laravel order by date not working
- How to call controller function from view in Laravel
- Laravel create multiple records in Pivot table
- Array to string conversion laravel blade
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- How to add dynamic page title in Laravel view
- How to get specific columns using Laravel eloquent methods
- How to get the random value form a specific column in laravel ?
- How to avoid duplicate entries in pivot table in Laravel
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Insert current date time in a column using Laravel
- How to pass data to multiple partial view files in laravel
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- Count all and get 10 records after where condition in laravel
- Multiple Level eager loading in Laravel
- Include External CSS and JS file in Laravel
- Laravel form request validation
- How to get count of all records created at yesterday
- Get today records in Laravel
- Post model with title and body in laravel 8
- Class 'App\Http\Controllers\User' not found
- How to get date from created_at field in laravel
- How to send email in laravel
- Display success message in laravel
- How to get file extension from input type file in laravel