
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.
Answers 1
-
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')); }
0
Random Code Snippet Queries: Laravel
- How to insert multiple rows in mysql using loop in laravel?
- Laravel get single row by id
- How to get user information using hootlex/laravel-friendships package in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Route [password.request] not defined
- Save or update pivot table data with additional column in Laravel
- Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
- Get last year created records in Laravel
- Class "App\Http\Controllers\Auth\Verified" not found
- How to decrypt laravel password
- Laravel get count with where condition
- There are no commands defined in the "route:" namespace
- Create a record if not exist in laravel
- How to return error message from controller to view in laravel
- Global scope in Laravel with example
- How to call model in blade laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- How to get route method name in Laravel
- Attempt to read property "avatar" on null in Laravel
- PhpMyAdmin - Error The mysqli extension is missing
- Extra Filter Query on Relationships in Laravel
- Target class [HomeController] does not exist
- How to check data inserted or deleted in pivot after toggle method
- Generate random string lowercase in Laravel
- Insert current date time in a column using Laravel