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

Controller

app\Http\Controllers\TodoController.php


namespace App\Http\Controllers;

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

class TodoController extends Controller
{
    public function index()
    {
        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;
    }
}

 

為什麼要這樣呢?Posts::create($request->all());

因為如果你的表單的input有100個,你只要寫這一行,就解決了

就不用在接參數時,再複製貼上100次的input的name,快速,少寫代碼,就是它的用意

 

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

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

T.E的Laravel

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