就是用model::all(),就可以取得這個資料表的所有的資料
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();
dd($posts);
return view('todo.index');
}
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;
}
}
dd() 就會列出來collection的資料
範例如下
想對外分享這則貼文嗎?運用網址更方便呦~