分享 推播通知
目前身份: 訪客

Controller

app\Http\Controllers\TodoController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Posts;

class TodoController extends Controller
{
    public function index()
    {
        $posts = Posts::all();

        return view('todo.index', [
            'posts' => $posts
        ]);
    }

    public function update(Request $request)
    {
        // $posts = new Posts();
        // $posts->post_name = $request->post_name;
        // $posts->save();

        // $obj = Posts::create([
        //     'post_name' => $request->post_name
        // ]);

        $obj = Posts::create($request->all());

        return $obj;
    }
}

 

主要就是這一行

 

return view('todo.index', [
            'posts' => $posts
        ]);

就可以輸入到view

 

而view要呈現的方式,就是用這樣的方式來接

 

@foreach ($posts as $post)
    

{{ $post->id .".". $post->post_name }}

@endforeach

 

最後結果的畫面:


 

2
T.E的Laravel 發表在 留言 (0) 人氣 (1347)
Laravel 學習
分享給朋友
網址

想對外分享這則貼文嗎?運用網址更方便呦~

T.E的Laravel

關於
專門記錄學習Laravel的過程與經歷,與突破困難點時的解決方法,和專家的經驗分享、各種知識點,整個學習Laravel的過程,就是自我提昇能力的過程。
貼文分類
最新貼文
誰來我家
  • 06-03  訪客(217.182.175.*)
  • 06-03  訪客(3.227.251.*)
  • 06-03  訪客(185.191.171.*)
  • 06-03  訪客(185.191.171.*)
OnceHit© 2023
載入中...